我有一个自定义表格视图单元格,其中包含自动布局建议的约束。在故事板中,所有约束都标有蓝色线条,表示它们没有错误。 tableview启动很好,布局有效,但是一旦我按下单元格来激活segue,我得到这个:
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.
我没有添加任何添加或删除布局约束的代码。所有约束都是通过自动布局自动添加的。
错误仅在我点击单元格时显示,该单元格激活segue以将用户带到下一个视图。当我点击后退按钮时,tableview返回但没有任何约束。
在属性检查器中将segue设置为Show(例如Push)。
以下是该消息的其余部分:
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7ff1c276fec0 UIImageView:0x7ff1c2496b40.top == UITableViewCellContentView:0x7ff1c2496630.topMargin + 15>",
"<NSLayoutConstraint:0x7ff1c276ff10 UIImageView:0x7ff1c2496b40.centerY == UITableViewCellContentView:0x7ff1c2496630.centerY>",
"<NSLayoutConstraint:0x7ff1c24c9a70 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c2496630(43.5)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff1c276ff10 UIImageView:0x7ff1c2496b40.centerY == UITableViewCellContentView:0x7ff1c2496630.centerY>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-01-06 11:35:58.645 FitLift[4174:130902] 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:0x7ff1c2494c00 UIImageView:0x7ff1c277c070.top == UITableViewCellContentView:0x7ff1c277bfa0.topMargin + 15>",
"<NSLayoutConstraint:0x7ff1c24a3360 UIImageView:0x7ff1c277c070.centerY == UITableViewCellContentView:0x7ff1c277bfa0.centerY>",
"<NSLayoutConstraint:0x7ff1c24b7010 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c277bfa0(43.5)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff1c24a3360 UIImageView:0x7ff1c277c070.centerY == UITableViewCellContentView:0x7ff1c277bfa0.centerY>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-01-06 11:35:58.646 FitLift[4174:130902] 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:0x7ff1c24c4390 UIImageView:0x7ff1c24bc880.top == UITableViewCellContentView:0x7ff1c24bc3d0.topMargin + 15>",
"<NSLayoutConstraint:0x7ff1c24c43e0 UIImageView:0x7ff1c24bc880.centerY == UITableViewCellContentView:0x7ff1c24bc3d0.centerY>",
"<NSLayoutConstraint:0x7ff1c24c7880 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ff1c24bc3d0(43.5)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff1c24c43e0 UIImageView:0x7ff1c24bc880.centerY == UITableViewCellContentView:0x7ff1c24bc3d0.centerY>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
答案 0 :(得分:1)
从错误日志中,似乎两个冲突的约束是图像视图的顶部约束和centerY约束。只选择一个 - iOS会混淆分配给图像视图的y坐标的值。您希望图像视图距离顶部一定距离,还是距离超视图的垂直中心一定距离?
作为一般规则,如果您希望UI看起来像您想要的那样,请不要让Xcode为您自动添加约束。自己定义。我们在这里无法真正帮助您,因为我们不知道Xcode添加的其他约束但不会发生冲突。
答案 1 :(得分:1)
尝试将一个垂直约束优先级降低到999或更低。
"<NSLayoutConstraint:0x174091d00 V:|-(10)-[UILabel:0x14562e580'This'] (Names: '|':UITableViewCellContentView:0x17418d5b0 )>", "<NSLayoutConstraint:0x174091e40 UITableViewCellContentView:0x17418d5b0.bottomMargin >= UILabel:0x14562e580'This'.bottom + 200>", "<NSLayoutConstraint:0x17408c940 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17418d5b0(43.5)]>"
我得到了这个,注意到最后一个,封装高度43.5,我猜它是默认高度,如果你的垂直约束不适合43.5,那么就会抛出错误。我仍然不确定自我调整细胞的工作原理,但降低优先级会使警告无效。我测试了一个比43.5短的细胞,它也使它沉默。
答案 2 :(得分:0)
我有一个类似的问题,它通过设置tableview的estimatedRowHeight来修复。默认的43.5甚至不足以覆盖我设置的固定点数(例如,单元格中的顶部标签距离单元格顶部10个点,底部标签距离底部10个点,行间距为10个点标签等)