刷新UICollectionView
有没有人知道如何重新加载/刷新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 } }];
所有预先计算好的animation。 最好的做法是首先删除并添加所有元素,以避免冲突。