iOS --- UICollectionView中使用reloadItemsAtIndexPaths进行局部cell更新

来源:互联网 发布:ubuntu控制台关机 编辑:程序博客网 时间:2024/06/13 06:30

UICollectionView与UITableView类似,都可以使用reloadData来进行cell内容的更新。然而如果想要进行局部cell更新呢?

UICollectionView

可以采用reloadItemsAtIndexPaths方法。

[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];

传入参数就是要刷新的cell所在的indexPath组成的数组。
但,reloadItemsAtIndexPath默认会有一个动画的过程,cell内容更新的瞬间会出现原内容与新内容重叠的情况。那么使用如下方式取消该动画即可:

[UIView performWithoutAnimation:^{    [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];}];

UITableView

UITableView的reloadSections方法也有同样的情况:

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];

而使用reloadData进行全部cell的更新,则没有这个默认的动画过程。

0 0
原创粉丝点击