2013-03-14 36 views
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自动布局所指的元素。所以我回到故事板,并将我的tableviewcell中的每个UI元素分配给Restoration Id字段中的标识符。我在某处读过错误消息中的十六进制数字,然后将其替换为分配给相应UI元素的名称。但不幸的是,这并没有发生。那么,我在这里做错了什么,或者我错过了什么?

+0

设置标识符应该可以工作。但是你总是可以在调试器中运行'po 0x1ede4320',甚至可以在'po [0x1ede4320 text]'或'p [0x1ede4320 frame]'上运行'看看它是否有助于识别它们。 – paulmelnikow 2013-03-14 19:19:44

+0

无法在iOS中设置视图标识符。主要失败,苹果! – phatmann 2013-04-15 16:14:40

回答

0

我检查了导致错误的布局约束断点。

如果我没看错的,然后你的布局可能看起来像: enter image description here

所以它看起来你已经设置的限制,如:

• 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 + 160像素的Y + 7

似乎它总被越来越多的是300这是你的和你的高度imageView1和imageView2中心Y都试图将中心匹配到0.