前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用reloadRowsAtIndexPaths刷新单个cell 跳动问题

用reloadRowsAtIndexPaths刷新单个cell 跳动问题

作者头像
honey缘木鱼
发布2019-07-26 11:09:39
3.9K0
发布2019-07-26 11:09:39
举报
文章被收录于专栏:娱乐心理测试娱乐心理测试

一个很常见的需求就是在一个cell上点赞,评论等操作时,需要刷新单个cell对象,常用的方法即为:

代码语言:javascript
复制
  [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:index inSection:0],nil] withRowAnimation:UITableViewRowAnimationNone];

仅仅这行代码会引起cell上下跳动的问题,原因是 上述刷新过程中,虽然我们已经设置UITableViewRowAnimationNone,但任然会默认添加隐式动画效果。 解决办法:去掉动画效果。

方法1:(支持iOS7+)

代码语言:javascript
复制
  [UIView performWithoutAnimation:^{
            [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:index inSection:0],nil] withRowAnimation:UITableViewRowAnimationNone];
        }];

方法2:

代码语言:javascript
复制
[UIView animateWithDuration:0 animations:^{
    [collectionView performBatchUpdates:^{
        [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
    } completion:nil];
}];

方法3:(仅用于iOS11以后)

代码语言:javascript
复制
[UIView setAnimationsEnabled:NO];
        [self.tableView performBatchUpdates:^{
             [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:index inSection:0],nil] withRowAnimation:UITableViewRowAnimationNone];
        } completion:^(BOOL finished) {
            [UIView setAnimationsEnabled:YES];
        }];
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.07.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档