UITableViewCell中UILabels的布局警告不明确

我在UITableViewCell有两个相邻的UILabel视图。 左边有一条线,右边可以有多条线,并使用剩下的任何水平空间。 两个标签距离单元格顶部的距离相同。 单元格的高度由正确标签的高度决定。 在某些情况下,我在右边的UILabel上面和下面看到了不必要的额外空间,因此它们不是顶端alignment的。 hasAmbiguousLayout它,我发现hasAmbiguousLayout为这两个标签返回YES

当我在debugging器中调用constraintsAffectingLayoutForAxis时,我得到以下输出:

 (lldb) po [0x7b769520 constraintsAffectingLayoutForAxis:0] <__NSArrayM 0x7b6cb340>( <NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0] (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>, <NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number'] (Names: '|':UITableViewCellContentView:0x7b768fc0 )>, <NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750> ) 

对于位于第一个UILabel右侧的第二个UILabel ,我得到这个:

 (lldb) po [0x7b769710 constraintsAffectingLayoutForAxis:0] <__NSArrayM 0x7b6cb9e0>( <NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750>, <NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0] (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>, <NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number'] (Names: '|':UITableViewCellContentView:0x7b768fc0 )>, <NSLayoutConstraint:0x7b76b230 H:[UILabel:0x7b769520'Number']-(15)-[UILabel:0x7b769710'Q12472']>, <NSLayoutConstraint:0x7b76ab90 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7b768fc0(320)]>, <NSLayoutConstraint:0x7b76b310 UILabel:0x7b769710'Q12472'.trailing == UITableViewCellContentView:0x7b768fc0.trailing - 15> ) 

任何人都可以根据上面的输出解释为什么这些标签有一个模糊的布局?

更新: NSAutoresizingMaskLayoutConstraint约束属于单元格的contentView 。 这两个标签都已经设置translatesAutoresizingMaskIntoConstraintsNO

更新2:这里是我对contentView和两个标签的约束:

 2015-02-26 07:35:25.559 contentView constraints: ( "<NSLayoutConstraint:0x7be541e0 V:|-(8)-[UILabel:0x7be537d0] (Names: '|':UITableViewCellContentView:0x7be535a0 )>", "<NSLayoutConstraint:0x7be54240 H:|-(15)-[UILabel:0x7be537d0] (Names: '|':UITableViewCellContentView:0x7be535a0 )>", "<NSLayoutConstraint:0x7be54310 V:|-(8)-[UILabel:0x7be53990] (Names: '|':UITableViewCellContentView:0x7be535a0 )>", "<NSLayoutConstraint:0x7be54340 H:[UILabel:0x7be537d0]-(15)-[UILabel:0x7be53990]>", "<NSLayoutConstraint:0x7be54370 UILabel:0x7be53990.trailing == UITableViewCellContentView:0x7be535a0.trailing - 15>", "<NSLayoutConstraint:0x7be543c0 UILabel:0x7be53990.bottom == UITableViewCellContentView:0x7be535a0.bottom - 8>", "<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>", "<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>", "<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>", "<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>" ) 2015-02-26 07:35:25.560 left label constraints: ( "<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>", "<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>" ) 2015-02-26 07:35:25.561 right label constraints:( "<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>", "<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>" ) 

这是一张图片,显示我有什么限制和出了什么问题:

在这里输入图像说明

我解决了它通过添加正确的UILabel

 [self.bodyLabel setContentHuggingPriority: UILayoutPriorityFittingSizeLevel forAxis: UILayoutConstraintAxisHorizontal]; 

另一件事是我正在testingupdateConstraints模糊性,而我应该在layoutSubviews

啊! 你有没有closurestranslatesAutoresizingMaskIntoConstraints属性cell.contentView的视图层次结构中的每个子视图?

输出显示您的自动布局与默认自动调整行为之间的冲突证据。 在xib中,这可以closures所有与checkbox,但在代码中,你必须在每个视图级别。