iOS:无法同时满足约束

时间:2014-06-29 01:17:05

标签: ios constraints autolayout nslayoutconstraint

我已经看到了对没有正确设置约束的问题的共同回应。但是,我已经解决了Interface Builder中的所有歧义,并且所有约束似乎都可以。我不确定接下来要检查什么。我甚至无法分辨它的来源。我没有在代码中设置任何约束。

我该怎样做才能弄清楚它的来源? 如果Interface Builder没有报告任何歧义,可能是什么原因?

以下是具体错误:

2014-06-28 19:54:36.070 Prayer Feed[4497:60b] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x178290360 H:[UIImageView:0x13ee32490(20)]>",
    "<NSLayoutConstraint:0x1782904f0 UITableViewCellContentView:0x178166840.centerX == UIImageView:0x13ee32490.centerX + 62>",
    "<NSLayoutConstraint:0x178290540 H:|-(52)-[UIImageView:0x13ee32490]   (Names: '|':UITableViewCellContentView:0x178166840 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x170286d60 h=--& v=--& H:[UITableViewCellContentView:0x178166840(247)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178290360 H:[UIImageView:0x13ee32490(20)]>

我知道代码中的两个地方,我有一个UIImageView约束到20x20,但同样,IB告诉我一切都很好。

1 个答案:

答案 0 :(得分:2)

这是问题所在的部分:

<NSAutoresizingMaskLayoutConstraint:0x170286d60 h=--& v=--& H:[UITableViewCellContentView:0x178166840(247)]>

需要关闭此遮罩。

我认为默认情况下,对于有约束的IB元素,该掩码是关闭的。所以我假设你在代码中做了些什么。您可以使用以下代码将其关闭:

contentView.translatesAutoresizingMaskIntoConstraints = NO

如果这真的只是IB,那么我想知道你在创建表格单元格时使用的代码。

相关问题