Objective-c – ios 8 (UITableViewCell) : Constraints ambiguously suggest a height of zero for a tableview cell’s content view

autolayoutios8objective cuitableview

I have a tableview using auto layout constraints , every thing is working in iOS 7 but when i tested in iOS 8 get me the below warning

Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.

After i made a profound investigations about this issue i found should add the below lines in viewdidload for iOS8 only

 self.tableView.rowHeight = UITableViewAutomaticDimension;

 self.tableView.estimatedRowHeight = 87;

After that still i get this warning and the height of cell isn't correct which is not take the height from Storyboard

For further info about UITableViewCell find below our constraints for content view cell

-(void) updateConstraints {
    [super updateConstraints];


    if(!didSetupConstraints ) {
       didSetupConstraints = YES;


    [self.contentView removeConstraints:self.contentView.constraints];
    // Interval Title
    //Leading
    constraint = [NSLayoutConstraint constraintWithItem:self.intervalTitle attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier: 1.0 constant:0.0];
        [self.contentView addConstraint:constraint];

     //Top
    constraint = [NSLayoutConstraint constraintWithItem:self.intervalTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.marketLocationTitle attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
        [self.contentView addConstraint:constraint];
}

Best Answer

Auto Layout is right on that one. It's impossible to calculate cell's height from .CenterX and .Top for the label. One way to resolve the problem would be removing the existing .CenterX constraint and adding a new .Bottom constraint. That way, Auto Layout could easily calculate cell's height.

Related Topic