有人知道如何在显示集合视图时重新加载/刷新UICollectionView吗?基本上,我正在为UITableview寻找类似于标准reloadData方法的东西。
您只需调用:
[self.myCollectionView reloadData];
单个部分和项目也可以重新加载:
[self.myCollectionView reloadSections:indexSet];
[self.myCollectionView reloadItemsAtIndexPaths:arrayOfIndexPaths];
[self.collectionView reloadData];
正确且最好的方法是使用
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
}
}];
所有的东西都被预先计算好了。最佳做法是先删除所有元素,然后再添加,以避免冲突。