UITableViewCell: Custom Row Height for prototype cell

Brabbeldas picture Brabbeldas · Aug 16, 2012 · Viewed 17.9k times · Source

In my storyboard file I am designing multiple prototype cells in a UITableView. Each cell has its own unique Cell Identifier.

Depending on the section and the row I dequeue one of the prototype cells in method - tableView:cellForRowAtIndexPath:

For most of the prototype cells I have not changed the Row Height. On my storyboard, their height seems to be determined by the property 'Row Height' under 'Size Inspector' of UITableView.

For one prototype cell I have changed the height through the property 'Row Height' under 'Size Inspector' of the specific UITableViewCell. The checkbox 'Custom' is also checked.

On my storyboard this seem to work well. But during runtime when my cells are being dequeued and added to the TableView, all cells get the default row height.

Now, I am aware of the method tableView:heightForRowAtIndexPath: which is being mentioned in other posts but it seems a little odd to use as I am setting a custom row height in my storyboard already.

Does somebody know why this property is not working? Is this property maybe mend to be used in different situations?

Thanks

Answer

enreas picture enreas · Jan 22, 2014

If you want to use Interface Builder in Xcode 5 to change the height of the rows in a table view without code you can do it in two places:

  • Select the table view, show the Size inspector and type it in Row Height, in the Table View Size section.

Default row height

  • Select the prototype cell, show the Size inspector, check Custom in the Table View Size section and type the row height in the associate text field.

Custom row height

Could it be that you're using the second method? Try to use the first method to set the default height of all the rows in the table view and the second to tell Interface Builder about the exceptions.