iOS8 - constraints ambiguously suggest a height of zero iOS8 - constraints ambiguously suggest a height of zero objective-c objective-c

iOS8 - constraints ambiguously suggest a height of zero


Forcing a return height and estimated height made the warning disappear in my case.

- (CGFloat)tableView:(UITableView *)tableView            estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {    return 44;}- (CGFloat)tableView:(UITableView *)tableView            heightForRowAtIndexPath:(NSIndexPath *)indexPath {    return 44;}

Another solution where you don't need the two overrides is simply to use self.tableView.rowHeight = 44; in your loadView or init method.


What can also be done is adding vertical constraints from the top and to the bottom of the content view. This will make autolayout happy (because he now knows how to calculate the height of the cell himself).


If you're using autoLayout constraints and UITableViewAutomaticDimension, this error is not some erroneous problem to be discarded by overriding your height in code. It means that determining the cell height automatically isn't working because you don't have the proper vertical constraints needed.

If you're like me and were getting this error and needed help identifying which cell was throwing the error, you can add the following line right before the return of your 'heightforRowAtIndexPath' method.

NSLog(@"Section %ld Row %ld", (long)[indexPath section], (long)[indexPath row]);

This will print out a long list of sections and rows, but the error will appear immediately following the particular cell that is causing the error, and you can quickly identify which cell is causing the problem and fix your constraints accordingly. This is particularly helpful for static cells. Overriding the height with a manually entered number will work if you're not using autoLayout and automatic cell heights, but will essentially disable these features which is a very poor solution if its something you're trying to utilize.

If you weren't previously using the 'heightForRowAtIndexPath' method but want to debug this error without undoing your UITableViewAutomaticDimension setting, simply add this to your code:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    NSLog(@"Section %ld Row %ld", (long)[indexPath section], (long)[indexPath row]);    return UITableViewAutomaticDimension;}