3

我收到一个我不明白的自动布局错误:

2013-03-14 18:30:48.842 driver[7177:907] 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:0x1ede73e0 UILabel:0x1ede4320.top == PriceCell:0x1edcd0c0.top + 160>",
    "<NSLayoutConstraint:0x1ede7460 V:[UILabel:0x1ede4320]-(7)-[UIImageView:0x1ede45d0]>",
    "<NSLayoutConstraint:0x1ede74a0 UIImageView:0x1ede45d0.centerY == UIImageView:0x1f856810.centerY>",
    "<NSLayoutConstraint:0x1ede7880 UIImageView:0x1f856810.top == PriceCell:0x1edcd0c0.top + 30>",
    "<NSLayoutConstraint:0x1ede78c0 UIImageView:0x1f856810.bottom == PriceCell:0x1edcd0c0.bottom>",
    "<NSAutoresizingMaskLayoutConstraint:0x1f83f340 h=--& v=--& V:[PriceCell:0x1edcd0c0(300)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1ede7460 V:[UILabel:0x1ede4320]-(7)-[UIImageView:0x1ede45d0]>

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.

问题:从错误列表中我无法确定自动布局所指的 ui 元素。所以我回到我的 Storyboard 并在我的 tableviewcell 中的每个 UI 元素中分配一个 Identifier 在字段 Restoration Id 中。我在某处读到错误消息中的十六进制数字然后替换为我分配给相应 ui 元素的名称。但不幸的是,这并没有发生。那么我在这里做错了什么,或者我错过了什么?

4

1 回答 1

0

我已经检查了导致错误的布局约束中断。

如果我没有错,那么您的布局可能如下所示: 在此处输入图像描述

所以看起来你已经设置了约束,比如:

•   Vertical space between cell top and label top is 160. So your label will be 160 px down from cell top.
•   Then you have set vertical space between label and imageView1 is 7 px.
•   Then you made centre Y between imageView1 and imageView2 to 0 px. So their centre will be same.
•   Then you set vertical space between imageView2 and cell top is 30 px.
•   Then you set vertical space between image view bottom and cell bottom is 0 px.
•   It seems that your cell height is 300 px.

所有这些约束都是为了满足你的一个约束而打破的。

那么这里会发生什么来满足“ 160 + label.height + 7 + UIImageView1.height ”的约束。

好吧,您的单元格高度似乎小于 label + imageView1 + 160 px of y + 7 的总高度。

似乎它的总高度超过了 300,这是您的单元格的高度,并且您的 imageView1 和 imageView2 中心 Y 都试图将中心匹配为 0。

于 2015-04-13T13:42:23.087 回答