Providing a nonnegative estimate of the height of rows can improve the performance of loading the table view. If the table contains variable height rows, it might be expensive to calculate all their heights when the table loads. Estimation allows you to defer some of the cost of geometry calculation from load time to scrolling time.
The default value is automaticDimension, which means that the table view selects an estimated height to use on your behalf. Setting the value to 0 disables estimated heights, which causes the table view to request the actual height for each cell. If your table uses self-sizing cells, the value of this property must not be 0.
When using height estimates, the table view actively manages the contentOffset and contentSize properties inherited from its scroll view. Do not attempt to read or modify those properties directly.
UITableView引用预估高度机制是为了推迟未显示cell的高度计算工作,提高UITableView加载性能,很好的机制,但是在使用中可能会带来意外的bug。
通过storyboard构建的订单列表页面,在xib中设置了estimatedRowHeight(默认开启、高度为auto),在该页面触发reloadData()之后,发现有时候cell莫名的滚动到了其他位置,只能在storyboard中设置estimatedRowHeight为0或者代码中tableView.estimatedRowHeight = 0来关闭预估高度(不是在UITableViewDelegate中设置)
四个预估高度:
- UICollectionViewFlowLayout.estimatedItemSize
- UITableView.estimatedRowHeight
- UITableView.sectionHeaderHeight
- *UITableView.estimatedSectionFooterHeight