如何删除所有项目并向UICollectionView添加新项目? [英] How to remove all items and add new items to UICollectionView?
本文介绍了如何删除所有项目并向UICollectionView添加新项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在某些事件中,
我想删除一个uicollectionview中的所有单元格,并添加新的单元格。(它将作为网络的结果填充)电话)
I'd like to remove all cells in a uicollectionview, and add new cells.(which will be populated as a result of a network call)
我尝试使用deleteItemsAtIndexPaths。
reloadSections,deleteSections / insertSections。
I tried using deleteItemsAtIndexPaths. reloadSections, deleteSections/insertSections.
他们每个人都崩溃了我的应用程序。
Each of them crashed my app.
以下是我的代码。
NSMutableArray* indexPathArray = [[NSMutableArray alloc] init];
for(int i=0; i < [self.jsonAlbumImageArray count]; ++i)
{
NSIndexPath* newPath = [NSIndexPath indexPathForRow:i inSection:0];
[indexPathArray addObject: newPath];
}
[self.jsonAlbumImageArray removeAllObjects];
if(indexPathArray.count > 0 )
{
[self.collectionView performBatchUpdates:^{
[self.collectionView deleteItemsAtIndexPaths:indexPathArray];
}
completion: nil];
}
// NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
// NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:0];
// [self.collectionView reloadSections:indexSet];
[self get_IMAGE_LIST_FROM_SERVER];
推荐答案
是的,正如Jonathan所说,我想你想要什么要做的是用新数据更改数据源,只需刷新或重新加载UICollectionView。
Yeah, as Jonathan said, I think what you want to do is change your datasource with the new data and simply "refresh" or reload the UICollectionView.
这篇关于如何删除所有项目并向UICollectionView添加新项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文