This difference becomes more meaningful when you have some custom cells which their height is different from most of your other cells. In that case the OS use estimatedHeightForRowAt
as a default (This optimizes your loading time), but then if specified a different height for a row then it would use that.
As for what to put there:
If there is no variation then you put the same 300. Basically you put your default/most expected height there. For the heightForRowAt depending on your needs you may want to do switch based on section/row and change height. If don't have any variations then still just put 300 there
I'm not sure if this is why you asked or not, but if you were asking this because you had dynamic tableViewCells with different heights, then the solution is:
- Use Auto Layout when creating your table view cells.
- Set the tableview
rowHeight
to UITableViewAutomaticDimension
.
- Set the
estimatedRowHeight
or implement the height estimation delegate method.
Basically do:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 80 // or any other number that makes sense for your cells
self.tableView.rowHeight = UITableViewAutomaticDimension
}
For more see this RW Tutorial and this high voted question
NOTE
If you don’t give the estimatedRowHeight
then tableview will dequeue a lot more cells, because it’s trying to be smart and needs to prepare itself for smooth scrolling. It will trigger both your cellForRow
& willDisplay
callbacks
If you give estimatedRowHeight
a value, then it won’t dequeue cells offscreen anymore