您的位置:首页 > 产品设计 > UI/UE

iOS UICollectionView 和 UITableView cell更新 详解

2017-01-07 21:24 411 查看
1> 更新全部数据
UICollectionView 与 UITableView类似,都可以使用 reloadData 方法来进行所有 cell内容的更新,reloadData 过程没有默认的动画过程

2> 更新特定 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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS objective-c