23

有谁知道在显示集合视图时如何重新加载/刷新 UICollectionView?基本上我正在寻找类似于 UITableview 的标准 reloadData 方法的东西。

4

3 回答 3

51

你可以打电话:

[self.myCollectionView reloadData];

个别部分和项目也可以重新加载:

[self.myCollectionView reloadSections:indexSet];
[self.myCollectionView reloadItemsAtIndexPaths:arrayOfIndexPaths];
于 2013-02-07T01:58:57.813 回答
10
[self.collectionView reloadData];
于 2013-12-21T21:48:59.597 回答
1

正确和最好的方法是使用

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
    }
}];

并且所有内容都被预先计算为一个很好的动画。最佳做法是先删除然后添加所有元素,以避免冲突。

于 2016-11-11T11:47:25.547 回答