【发布时间】:2015-04-11 15:55:30
【问题描述】:
我的一个视图控制器出现了一些非常奇怪的行为。
我正在从不同选项卡中的两个不同UITableViews 导航到同一个控制器(具有不同的实例)。
当它通过点击UITableViewCell 显示时,一切都很好,没有错误显示。如果我打开控制器并通过选择另一个选项卡离开它,然后通过按原始选项卡导航回到它,我会收到大量 NSLayoutConstraint 错误。
我的单元格中实际上没有任何约束,并且故事板中单元格的内容视图上没有任何 UI 元素,因为我正在以编程方式添加所有这些元素。我也没有在代码中定义任何约束。
完整的错误是 here,因为它太大而无法合理地粘贴到 SO。
摘录如下:
2015-04-11 16:49:23.889 TradingPost[6982:60b] 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:0x155e5250 H:[UILabel:0x155d8150(158)]>",
"<NSLayoutConstraint:0x155ed9e0 H:|-(8)-[UILabel:0x155d8150] (Names: '|':UITableViewCellContentView:0x155d4a80 )>",
"<NSLayoutConstraint:0x155eda30 H:[UILabel:0x155d8150]-(47)-[UIView:0x155e01a0]>",
"<NSLayoutConstraint:0x155f1bc0 UIView:0x155e01a0.trailing == UITableViewCellContentView:0x155d4a80.trailing - 8>",
"<NSAutoresizingMaskLayoutConstraint:0x156b7640 h=--& v=--& H:[UITableViewCellContentView:0x155d4a80(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x155e5250 H:[UILabel:0x155d8150(158)]>
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 生成代码并从情节提要中删除了所有约束。在这一点上,我怀疑巫术。
【问题讨论】:
-
您是否检查/设置了所涉及视图的
translatesAutoresizingMaskIntoConstraints的值?
标签: ios objective-c uitableview autolayout nslayoutconstraint