【发布时间】:2014-04-16 17:18:23
【问题描述】:
所以基本上我有搜索方法“searchTableList”,得到我想要的结果后,我想重新加载 uicollectionview
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
// NSLog(@"Text change - %d",isSearching);
//Remove all objects first.
[filteredContentList removeAllObjects];
if([searchText length] != 0) {
isSearching = YES;
[self searchTableList];
}
else {
isSearching = NO;
}
[self.collectionView reloadData];
}
但是在“[self.collectionView reloadData]”之后什么都没有发生!
使用后,一直崩溃!
[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];
[self.collectionView reloadData];
我该怎么办,非常感谢!!! :D
错误信息是:
2014-04-16 18:24:35.684 SampleProject1[59602:60b] the item width must be less that the width of the UICollectionView minus the section insets left and right values.
2014-04-16 18:24:37.709 SampleProject1[59602:60b] *** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionView.m:3688
2014-04-16 18:24:37.713 SampleProject1[59602:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert item 0 into section 0, but there are only 0 items in section 0 after the update'
已修复:
基本上,我返回了一个未使用数组的计数,该数组的长度始终为 0,而不是相关数组!
所以我不得不改变这个:
if (isSearching) {
return [searchResult count];
} else {
return [self.tracks count];
}
到: if (isSearching) {
return [filteredContentList count];
} else {
return [self.tracks count];
}
然后在此之后我删除了所有 reloadData 术语并将其替换为:
[self.collectionView reloadData];
非常感谢大家!!
【问题讨论】:
-
如果崩溃,错误信息是什么?
-
@MarcMosby 刚刚更新了代码和错误信息 :)
-
Google 您的最后一条错误消息。只有原因文本。
-
代理分配是否正确?
-
@MarcMosby 非常感谢!!!!!
标签: ios objective-c cocoa-touch uikit uicollectionview