有没有人知道在UICollectionView显示的时候如何重新加载/刷新它?基本上我是在寻找类似于UITableView标准reloadData方法的东西。
有没有人知道在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
}
}];