Custom Cell Row Height setting in storyboard is not responding Custom Cell Row Height setting in storyboard is not responding ios ios

Custom Cell Row Height setting in storyboard is not responding


On dynamic cells, rowHeight set on the UITableView always overrides the individual cells' rowHeight.

But on static cells, rowHeight set on individual cells can override UITableView's.

Not sure if it's a bug, Apple might be intentionally doing this?


If you use UITableViewController, implement this method:

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

In the function of a row you can choose Height. For example,

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    if (indexPath.row == 0) {       return 100;    }     else {       return 60;    }}

In this exemple, the first row height is 100 pixels, and the others are 60 pixels.

I hope this one can help you.


For dynamic cells, rowHeight set on the UITableView always overrides the individual cells' rowHeight.

This behavior is, IMO, a bug. Anytime you have to manage your UI in two places it is prone to error. For example, if you change your cell size in the storyboard, you have to remember to change them in the heightForRowAtIndexPath: as well. Until Apple fixes the bug, the current best workaround is to override heightForRowAtIndexPath:, but use the actual prototype cells from the storyboard to determine the height rather than using magic numbers. Here's an example:

- (CGFloat)tableView:(UITableView *)tableView            heightForRowAtIndexPath:(NSIndexPath *)indexPath{    /* In this example, there is a different cell for       the top, middle and bottom rows of the tableView.       Each type of cell has a different height.       self.model contains the data for the tableview     */    static NSString *CellIdentifier;    if (indexPath.row == 0)         CellIdentifier = @"CellTop";    else if (indexPath.row + 1 == [self.model count] )        CellIdentifier = @"CellBottom";    else        CellIdentifier = @"CellMiddle";    UITableViewCell *cell =               [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];    return cell.bounds.size.height;}

This will ensure any changes to your prototype cell heights will automatically be picked up at runtime and you only need to manage your UI in one place: the storyboard.