我收到一条我不明白的Autolayout错误:
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.
问题:从错误列表中我无法确定autolayout指的是哪些ui元素。所以我回到我的故事板并在tableviewcell中为每个UI元素分配了Restoration Id字段中的Identifier。我已经在某处读到错误消息中的十六进制数被替换为我分配给相应ui元素的名称。但不幸的是,这种情况并没有发生。那么我在这里做错了什么,或者我错过了什么?
答案 0 :(得分: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”的约束,会发生什么。
看起来您的单元格高度小于标签+ imageView1的总高度+ y + 7的160 px。
似乎总数超过300,这是你的单元格的高度,你的imageView1和imageView2中心Y都试图将中心匹配为0.