Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell height is not changing in UITableView when changing it in Interface Builder

I am making a custom table cell with InterfaceBuilder. However, when I change the height in IB, the changes are not reflected in the running program. Is there anything else I need to do besides set the height in IB?

Thanks in advance.

like image 929
rustybeanstalk Avatar asked Oct 10 '11 06:10

rustybeanstalk


People also ask

How to increase tableView cell height?

To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we'll need to make use of automatic dimension property.

How do I populate UITableView?

There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.

What is indexPath in tableView Swift?

indexPath(for:)Returns an index path that represents the row and section of a specified table-view cell.


1 Answers

Changing the height of your custom cell in IB is not enough. The height of a row in a UITableView can be controlled in 2 ways

  1. Set the tableview.rowHeight property to the desired value if you know all cells will be the same height. You can also set this in IB if i'm not mistaken.

  2. Implement the UITableViewDelegate method

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

This method takes precedence, meaning that if you implement this method then the value you set in tableView.rowHeight is ignored.

like image 163
Andrei Stanescu Avatar answered Oct 01 '22 18:10

Andrei Stanescu