woutr_be woutr_be - 9 months ago 70
iOS Question

Dynamic table cell height

Using the storyboard, I've created a custom cell for my table view, I've also created a custom class for it with all my properties.

Now, what would be the best way in making the cells height dynamic, where is the best way to do this?
Should I do this in the custom class for the cell? Or in my table view controller?

I imagine it would make more sense to do this in the custom class, but then how should I do this?
Once a specific label is filled in, it should change the height of the cell

Answer Source

You cannot change the height of the cell from your custom drawing class.

You can do this in the viewController that has the UITableView only. Either by specifying a hardcoded row height for all cells, or by using the

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

and specifying a height for the cells here. If you want to have different heights for the cells, you should check the indexpath.row property and return the desired height value.

In case you want to change the height of an already drawn in screen cell, you will have to reload that cell to reflect the change using this:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation