美文网首页
tableView里面的contentSize计算不准确

tableView里面的contentSize计算不准确

作者: follow_er | 来源:发表于2020-11-24 19:14 被阅读0次

    问题: 想要直接获取tableView的contentSize中的高度。
    tableView.reloadData()是一个异步操作,所以在reloadData后面直接获取高度会有一定的偏差。
    可以使用self.view.layoutIfNeeded() 强制layout,然后再获取。同时estimatedRowHeight = 0
    estimatedRowHeight: 看了文档,The default value is automaticDimension, which means that the table view selects an estimated height to use on your behalf. Set the value to 0 to disable estimated heights

    实测有可能这样设置了还是不好用,那么在初始化tableview之后就会需要先reloadData()一遍。

    相关文章

      网友评论

          本文标题:tableView里面的contentSize计算不准确

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