I have UITableView with one section (1 header view + 100 rows). Its vertical constraints are to top view's bottom and to superview's bottom (not bottom safe area).
I provided all the necessary heights manually with UITableViewDelegate:
- section header height
- first and last cell height
- other cells height
If I sum all these heights i get ~6000px but tableView.contentSize.height returns ~4500 until I scroll to the bottom of the table. And this happens even with default cells.
I understand that I can calculate everything manually but why table has wrong content size if all its inner element heights are predefined?
Found a solution for my case (when all the table items' heights are predefined): https://developer.apple.com/forums/thread/81895
It seems
heightForRowdelegate method determines the height of the row which is drawn/visible on the screen but is not properly involved incontentSizecalculation.estimatedHeightForRowAtlooks like the opposite method. It determines the height of the row forcontentSizecalculation but without ofheightForRowvisible rows have the default height.So it is necessary to implement both
heightForRowandestimatedHeightForRowAtmethods for this case.The same is for header/footer heights (if these items are displayed)