美文网首页
UITableView reloadData 后 content

UITableView reloadData 后 content

作者: NapoleonY | 来源:发表于2020-07-10 15:21 被阅读0次

原因

UITableView 在初始加载数据时,是通过估算得到的 contentSize,其中
estimatedRowHeightestimatedSectionFooterHeightestimatedSectionHeaderHeight 的值均为 automaticDimension

解决

  1. 首先将这几个值设为 0
    由于reloadData 是异步执行,因此想要在 reloadData 后获取执行部分操作,需要通过以下两种方式
  2. 如果是 iOS 11之后,直接调用 performBatchUpdates 方法
  3. iOS 11之前在主线程中设置contentOffset,当然这种方式不一定准确
    DispatchQueue.main.async {
            self.storeTable.contentOffset = CGPoint(x: 0, y: offsetY)
    }
    

相关文章

网友评论

      本文标题:UITableView reloadData 后 content

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