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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can just call:
[self.myCollectionView reloadData];
Individual sections and items can also be reloaded:
[self.myCollectionView reloadSections:indexSet];
[self.myCollectionView reloadItemsAtIndexPaths:arrayOfIndexPaths];
回答2:
[self.collectionView reloadData];
回答3:
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.