ios 刷新 UICollectionview
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14742106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refreshing a UICollectionview
提问by SNV7
Does anyone know how to reload/refresh a UICollectionView while the collection view is being displayed? Basically I'm looking for something similar to the standard reloadData method for a UITableview.
有谁知道如何在显示集合视图时重新加载/刷新 UICollectionView?基本上我正在寻找类似于 UITableview 的标准 reloadData 方法的东西。
回答by Firo
You can just call:
你可以打电话:
[self.myCollectionView reloadData];
Individual sections and items can also be reloaded:
还可以重新加载各个部分和项目:
[self.myCollectionView reloadSections:indexSet];
[self.myCollectionView reloadItemsAtIndexPaths:arrayOfIndexPaths];
回答by Irineu Licks Filho
[self.collectionView reloadData];
回答by Karsten
The correct and best way is to use
正确和最好的方法是使用
NSMutableArray *indexPaths = [NSMutableArray array];
//prepare some data
//batchupdate as block
[self.collectionView performBatchUpdates:^{
//operations like delete
[self.collectionView deleteSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, count)]];
[self.collectionView insertItemsAtIndexPaths:indexPaths];
} completion:^(BOOL finished) {
// call something when ready
}
}];
and all gets precomputed an nicely animated. The best practice is to first remove and than add all elements, to avoid conflicts.
并且所有都被预先计算出一个很好的动画。最佳做法是先删除然后添加所有元素,以避免冲突。