huddie96 huddie96 - 1 year ago 92
Objective-C Question

Dynamic UITableViewCell height not working

(iOS 8 with Storyboard)
I have a right detail UITableViewCell on my tableView.

In storyboard the Title and Right Detail labels are set to numberoflines = 0

My Code:

- (void)viewDidLoad {
[super viewDidLoad];
keyArray = [[NSMutableArray alloc]init];
self.table.estimatedRowHeight = 140.0;
self.table.rowHeight = UITableViewAutomaticDimension;
[spinner startAnimating];
[self cleanJson:prunedDictionary];


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

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;


At the end of cleanJson I run
[self.table reloadData]
The TableViewCell does resize but they all resize to the same size and it seems like the default size. (The reason I know they resize is because in Storyboard I set the height to 200 and they were all resized to a smaller size when the app ran)

Why aren't they resizing correctly?

Answer Source

The problem is that you are using a built in cell type and the built in title and detail labels. Those cell types are not self sizing.

You must use a custom cell and design it yourself, with constraints that size the cell from the inside out.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download