美文网首页
ios tableview 使用自动布局后刷新时页面跳动 闪烁问

ios tableview 使用自动布局后刷新时页面跳动 闪烁问

作者: FM_0138 | 来源:发表于2019-12-13 15:08 被阅读0次
  • 设置tableview为自适应高度
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0; 
  • 由于自适应每次刷新都会计算, 所以会造成闪烁,跳动, 将高度缓存下来就可以了
    • 定义一个字典, 存放高度
    @property (nonatomic, strong) NSMutableDictionary *cellHightDic;// 记录cell高度
    
    • tableView:willDisplayCell:orRowAtIndexPath:方法中记录cell的高度
    [self.cellHightDic setObject:@(cell.frame.size.height) forKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]];
    
    • tableView:estimatedHeightForRowAtIndexPath:方法中返回cell的高度
     - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
      CGFloat height = [[self.cellHightDic objectForKey:[NSString stringWithFormat:@"%ld_%ld",(long)indexPath.section, (long)indexPath.row]] floatValue];
      if (height == 0) {
          return 50;
      }
      return height;
     }
    

相关文章

网友评论

      本文标题:ios tableview 使用自动布局后刷新时页面跳动 闪烁问

      本文链接:https://www.haomeiwen.com/subject/btvfnctx.html