【问题标题】:Empty all cells from UICollectionView清空 UICollectionView 中的所有单元格
【发布时间】:2014-03-14 01:28:21
【问题描述】:

使用 iOS6 的新 UICollectionView 我如何能够在一个大循环中删除所有 UICollectionViewCell 对象?

假设我已经将所有数据加载到其中,我点击刷新,我想删除当前其中的所有内容,然后再次调用我的东西。

我发现deleteItemsAtIndexPaths 需要NSArray,那么我怎样才能将所有项目都放入其中?

【问题讨论】:

    标签: ios6 uicollectionview


    【解决方案1】:

    清除 UICollectionVew 的正确方法是简单地清除数据源,然后重新加载集合视图。

    所以如果你的数据源是一个数组:

    self.dataArray = nil;
    [self.collectionView reloadData];
    

    Boom,你被清除了。

    【讨论】:

    • 轰,崩溃,就我而言。
    • 可能想这样做:self.dataArray = []反对nil以防止崩溃
    【解决方案2】:

    事实证明我可以使用deleteSections 并将NSIndexSet 传递给它,形成0,0 的范围,它会删除唯一的部分。

    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 0)];
    [self.collectionView deleteSections:indexSet];
    

    我可能只使用indexSetWithIndex,但是当我这样做时,我的应用程序崩溃了。

    【讨论】:

    • 为什么 indexSetWithIndex:0 会崩溃?我遇到这个不知道为什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    相关资源
    最近更新 更多