美文网首页
解决UITableView刷新时跳动上移

解决UITableView刷新时跳动上移

作者: 风_iOSer | 来源:发表于2017-10-11 10:37 被阅读0次

昨天在项目中发现一个问题,一个列表滚动到底部时,刷新列表,会向上弹一下,百思不得其解,经过一番查询,原因是刷新列表时,tableView会重新计算高度,得到用缓存行高的办法如下:

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{


  NSString *key = [NSString stringWithFormat:@"%ld",indexPath.row];
  NSNumber *heigt = self.cellheightDic[key];
  if (heigt == nil) {
      heigt = @(100);
  }

    return heigt.floatValue;

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

  NSLog(@"heig = %ld",indexPath.row);

  NSString *key = [NSString stringWithFormat:@"%ld",indexPath.row];
  NSNumber *heigt = self.cellheightDic[key];
  if (heigt == nil) {
    heigt = @(self.cell.cellHeight);
    [self.cellheightDic setValue:heigt forKey:key];
    }
return heigt.floatValue;
}

相关文章

网友评论

      本文标题:解决UITableView刷新时跳动上移

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