Autolayout显示警告消息

时间:2014-02-20 14:49:17

标签: ios objective-c uitableview autolayout

我在自动布局方面遇到了一些问题。一切都显示正确,一切正常,但我在命令行中收到一些警告消息:

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:0xb6a60f0 H:[UIImageView:0xb645e40(75)]>",
"<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>",
"<NSLayoutConstraint:0xb6aaea0 H:|-(10)-[UIImageView:0xb645e40]   (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6c85c0 H:[UIView:0xb6c7350]-(7)-|   (Names: '|':UITableViewCellContentView:0xb6c1590 )>",
"<NSLayoutConstraint:0xb6d2270 H:[UIImageView:0xb645e40]-(8)-[UIView:0xb6c7350]>",
"<NSAutoresizingMaskLayoutConstraint:0xb6abd20 h=--& v=--& H:[UITableViewCellContentView:0xb6c1590(300)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0xb6d0e90 H:[UIView:0xb6c7350(220)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView 
listed in <UIKit/UIView.h> may also be helpful.

这是我的nib文件的外观:

enter image description here

正如你可以看到它的TableViewCell,我正在使用带有TextView(适用于iOS7)和AttributedTextView(适用于iOS6)的View(示例文本)!

问题是什么?

2 个答案:

答案 0 :(得分:2)

问题在于你有相互冲突的约束......有时,自动布局可能是一种痛苦。 当我遇到这种情况时,我通常会清除所有约束,并通过选择清除所有约束来重新开始。

之后你也可以选择“添加缺失的约束”,并希望XCode能够自动知道你想要做什么..实际上,XCode有50%的机会让它正确。

从你的屏幕截图来看,你看起来有太多的约束,所以另一个选择是尝试逐个删除,并捕捉那些“冲突”的约束。

clearing constraints

答案 1 :(得分:0)

为每个视图设置translatesAutoresizingMaskIntoConstraints = NO;这就是他想告诉你的。在运行期间,您有自己的约束和通用约束。猜猜我们会看到这个属性在升级的iOS版本中默认切换为NO。

相关问题