If all your rows are the same height, then you can set the rowHeight
property of your UITableView
instead of implementing tableView:heightForRowAtIndexPath:
. If you have rows of different heights, then you have to implement tableView:heightForRowAtIndexPath:
.
Neither of these methods will automatically return the height of the cell you defined in your NIB, as they get called before you start constructing cells in tableView:cellForRowAtIndexPath:
.
To use the height of the cell defined in your NIB, I recommend that you define a custom property of your controller called prototypeCell
, which will hold a single cell that never gets displayed on your table. In tableView:heightForRowAtIndexPath:
, check to see if prototypeCell
is nil. If it is, initialize it from your NIB. Then return prototypeCell.frame.size.height
.