ios 8 (UITableViewCell) : Constraints ambiguously suggest a height of zero for a tableview cell's content view

半世苍凉 提交于 2019-12-21 14:24:28

问题


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];
}

回答1:


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.



来源:https://stackoverflow.com/questions/26375890/ios-8-uitableviewcell-constraints-ambiguously-suggest-a-height-of-zero-for-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!