I have a UITableViewController. In viewDidLoad I set the rowHeight:
self.tableView.rowHeight = 43;
But then in cellForRowAtIndexPath, I check the height of the cell:
NSLog(@"bounds: w = %f, h = %f", cell.bounds.size.width, cell.bounds.size.height);
This prints a height of 44 and a width of 320. Anyone know why it would print a height of 44 instead of 43?
Thanks!
Simply put, the two things are independent of each other.
When you set
rowHeightin yourUITableViewobject, you are telling it how to render the table. The default value forrowHeightis 44.When you create a
UITableViewCellobject, as a subclass ofUIView, it has its own defaultframeandbounds, which includes aheight(andwidth). The default value forheightalso just happens to be equal 44.Your confusion arises because you have created a
UITableViewCellobject and you expected it to have aheightequal to the (not default)rowHeightproperty in yourUITableViewobject. How can it? It just came into existence!Like all
UIViews, until something comes along and explicitly changes itsheight, itsheightwon’t change.