繁体   English   中英

reloadData不适用于iOS7中的UICollectionView

[英]reloadData not working for UICollectionView in iOS7

所以基本上我有搜索方法“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 jargons并将其替换为:

[self.collectionView reloadData];

非常感谢!

  • 编写reloadItemsAtIndexPaths后,无需再次写入reloadData。
  • 使用主线程重新加载相应的集合View行。

代码片段:

[[NSOperationQueue  mainQueue]  addOperationWithBlock:^{

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

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

}];

检查willDisplayCell ...方法中的任何[collectionView reloadData]命令。 我已经在那里工作了一次,但是当我需要使用新数据集再次重新加载数据时,它不会再触发任何更多的willDisplayCell调用。

这一切都在主线上,这不是问题所在。 更像是溢出问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM