美文网首页
tableview 的刷新偏移问题 2022-01-08

tableview 的刷新偏移问题 2022-01-08

作者: iOS打怪升级 | 来源:发表于2022-01-08 17:54 被阅读0次
1. 增加了cell 个数据,调用reload 刷新,发现页面会自动滚动
解决方法:
///default is UITableViewAutomaticDimension, set to 0 to disable
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;

这个三个属性有点特殊,0表示禁用的意思,会和CGFLOAT_MIN 有区别;如果是手动计算高度的话,尽量不要用CGFLOAT_MIN 会有性能问题

2. tableview 顶部有间距 可以设置CGFLOAT_MIN解决 ,但是又不想影响性能的话,只能用0需要看方法2
解决方法1:
///default is UITableViewAutomaticDimension, set to 0 to disable
    self.tableView.estimatedRowHeight = CGFLOAT_MIN;
    self.tableView.estimatedSectionFooterHeight = CGFLOAT_MIN;
    self.tableView.estimatedSectionHeaderHeight = CGFLOAT_MIN;

解决方法2
  self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionFooterHeight =0;
    self.tableView.estimatedSectionHeaderHeight =0;

//    self.tableView.tableFooterView = [UIView new];//旧方法
//针对ios 11.0 以后用下面的比较好,不会又意外的间距产生
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];

相关文章

网友评论

      本文标题:tableview 的刷新偏移问题 2022-01-08

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