2012-10-28 178 views
1

使用iOS6的超酷UICollectionView我如何才能在大循环中删除所有UICollectionViewCell对象?假设我已经将所有的数据加载到它中,我点击刷新,我想删除当前内容,然后再次调用我的东西。清空UICollectionView中的所有单元格

我发现deleteItemsAtIndexPaths需要NSArray,所以我怎样才能把所有物品都放进去呢?

回答

3

原来我可以使用deleteSections并将NSIndexSet传递给它,使得范围为0,0,它将删除唯一的部分。

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

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

+0

为什么indexSetWithIndex:0崩溃?我遇到这个,不知道为什么 – Wingzero

2

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

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

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

繁荣,你清理出去。

相关问题