IOS 8(的UITableViewCell):约束隐约暗示的零一的tableview单元格的内容视图的高度 [英] ios 8 (UITableViewCell) : Constraints ambiguously suggest a height of zero for a tableview cell's content view

查看:524
本文介绍了IOS 8(的UITableViewCell):约束隐约暗示的零一的tableview单元格的内容视图的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自动布局约束有一个tableview中,每一件事情是工作在iOS的7,但是当我在iOS的测试8给我下面的警告

警告只有一次:器检测到的约束隐约暗示的零一的tableview单元格的内容视图的高度的情况。我们正在考虑的崩溃无意和使用标准高度来代替。

在我提出这个问题,我发现应该viewDidLoad中添加下面的线iOS8上了深刻的调查,只有

  self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 87;

这之后我依然得到这样的警告和细胞的高度是不正确不从故事板采取高度

有关在下面找到我们的内容视图单元格的限制有关的UITableViewCell进一步信息

   - (无效){updateConstraints
    [超级updateConstraints]
    如果(!didSetupConstraints){
       didSetupConstraints = YES;
    [self.contentView removeConstraints:self.contentView.constraints];
    //间隔名称
    //领导
    约束= [NSLayoutConstraint constraintWithItem:self.intervalTitle属性:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView属性:NSLayoutAttributeCenterX乘数:1.0常数:0.0];
        [self.contentView addConstraint:约束];     //最佳
    约束= [NSLayoutConstraint constraintWithItem:self.intervalTitle属性:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.marketLocationTitle属性:NSLayoutAttributeTop乘数:1.0常数:0.0];
        [self.contentView addConstraint:约束];
}


解决方案

自动布局是正确的那一个。这是不可能来计算 .CenterX .TOP 细胞的身高和标签。解决这个问题的方法之一是拆除现有的 .CenterX 约束,添加一个新的 .Bot​​tom 约束。通过这种方式,自动布局可以很容易地计算出细胞的高度。

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

解决方案

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.

这篇关于IOS 8(的UITableViewCell):约束隐约暗示的零一的tableview单元格的内容视图的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆