我看到对这个问题的普遍回答是没有正确设置约束。但是,我已经解决了 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 再次告诉我一切正常。
最佳答案
这是问题所在的部分:
<NSAutoresizingMaskLayoutConstraint:0x170286d60 h=--& v=--& H:[UITableViewCellContentView:0x178166840(247)]>
需要关闭此掩码。
我认为对于具有约束的 IB 元素,掩码在默认情况下是关闭的。所以我假设你用代码做了一些事情。您可以使用如下代码将其关闭:
contentView.translatesAutoresizingMaskIntoConstraints = NO
如果这真的只是 IB,那么我想知道您在创建表格单元格时使用了哪些代码。
关于iOS:无法同时满足约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24472356/