gpt4 book ai didi

ios - reloadData 不适用于 iOS7 中的 UICollectionView

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:22 33 4
gpt4 key购买 nike

所以基本上我有搜索方法“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];
}

收件人: 如果(正在搜索){

        return [filteredContentList count];

} else {
return [self.tracks count];
}

然后在这之后我删除了所有 reloadData 术语并将其替换为:

[self.collectionView reloadData];

非常感谢你们!!

最佳答案

  • 写完 reloadItemsAtIndexPaths 不需要再写重新加载数据。
  • 使用主线程重新加载相应的 Collection View 行。

代码片段:

[[NSOperationQueue  mainQueue]  addOperationWithBlock:^{

// Reload the respective collection view row using the main thread.

[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];

}];

关于ios - reloadData 不适用于 iOS7 中的 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23116065/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com