我正在尝试使用删除标签的常用方法并让自动布局调整所有内容。如何在运行时更改标签约束。但是,我在 UITableView标头中执行此操作。
当我设置其中一个标签的高度约束时:
self.labelAHeight.constant = 0;
结果是:
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:0xb0faad0 V:[UILabel:0xb0fa830(0)]>",
"<NSLayoutConstraint:0xb0772a0 V:[UILabel:0xb077300(58)]>",
"<NSLayoutConstraint:0xb076cc0 V:|-(0)-[UILabel:0xb0fa830] (Names: '|':UIView:0xb077660 )>",
"<NSLayoutConstraint:0xb076c90 V:[UILabel:0xb077300]-(0)-| (Names: '|':UIView:0xb077660 )>",
"<NSLayoutConstraint:0xb076c00 V:[UILabel:0xb0fa830]-(0)-[UILabel:0xb077300]>",
"<NSAutoresizingMaskLayoutConstraint:0xb06f030 h=--& v=--& V:[UIView:0xb077660(119)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xb0772a0 V:[UILabel:0xb077300(58)]>
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.
我试过[self.labelA setTranslatesAutoresizingMaskIntoConstraints:NO]
这没有帮助。
我试过[self.table.tableHeaderView setTranslatesAutoresizingMaskIntoConstraints:NO]
哪个崩溃了*** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
。可能,我在错误的地方执行此操作(就在设置约束常量之前)。
约束更改发生在哪里似乎并不重要,例如viewDidLoad
,或按钮处理程序。
看起来好像标题想要达到某个高度(<NSAutoresizingMaskLayoutConstraint:0xb06f030 h=--& v=--& V:[UIView:0xb077660(119)]>
基于其内容)并且如果内容发生更改,自动布局会变得非常不愉快。
任何人都可以帮助调试或建议如何解决它?(我尝试过 Instruments,但对添加和删除的所有约束感到困惑......)