项目中自定义Cell,控件使用autoLayout来设置约束,发现运行页面表现正常,但是控制台报如下错误:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
() look at each constraint and try to figure out which you don't expect;
() find the code that added the unwanted constraint or constraints and fix it.
(
<NSLayoutConstraint:0x10c30ee10 V:[UILabel:0x10c30ebb0'Label'(21.6667)]>,
<NSLayoutConstraint:0x10c30f9c0 V:[UIView:0x10c30ea20()]>,
<NSLayoutConstraint:0x10c30fab0 V:|-()-[UILabel:0x10c30ebb0'Label'] (Names: '|':UIView:0x10c30ea20 )>,
<NSLayoutConstraint:0x10c30fb00 V:[UILabel:0x10c30ebb0'Label']-()-[UILabel:0x10c30f080'Label']>,
<NSLayoutConstraint:0x10c30fb50 UILabel:0x10c30f080'Label'.height == UILabel:0x10c30ebb0'Label'.height>,
<NSLayoutConstraint:0x10c30fc90 V:[UILabel:0x10c30f3d0'Label']-()-| (Names: '|':UIView:0x10c30ea20 )>,
<NSLayoutConstraint:0x10c30fd80 V:[UILabel:0x10c30f080'Label']-()-[UILabel:0x10c30f3d0'Label']>
) Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x10c30ee10 V:[UILabel:0x10c30ebb0'Label'(21.6667)]> 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.
问题:
表示约束发生冲突,查看错误信息,其中一个label报约束冲突:
发现在cell中设置的label高度为21.6
但实际代码中计算的label高度为21.667,并设置label高度约束为21.667
说明label约束冲突了
解决办法:
在cell中找到这个label,找到这个label的高度约束,对其优先级进行减一操作,
以前是1000,改为999,即当xib中设置的高度约束与代码中更新的高度约束不一致时,
取代码中设置的值。