tableView里面的contentSize计算不准确
2020-11-24 本文已影响0人
follow_er
问题: 想要直接获取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()
一遍。