Do I need to set heightForRowAtIndexPath if I am using a custom UITableViewCell? In my NIB I have already set the cell height.
When I over-ride heightForRowAtIndexPath the contents of my cell don’t appear, even though it is set to the height defined in the NIB.
If I don’t over-ride heightForRowAtIndexPath the contents of the cell appear, but there is overflow since the default height is not large enough.
If all your rows are the same height, then you can set the
rowHeightproperty of yourUITableViewinstead of implementingtableView:heightForRowAtIndexPath:. If you have rows of different heights, then you have to implementtableView: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. IntableView:heightForRowAtIndexPath:, check to see ifprototypeCellis nil. If it is, initialize it from your NIB. Then returnprototypeCell.frame.size.height.