[报错]Unable to simultaneously satisfy constraints

项目中自定义Cell,控件使用autoLayout来设置约束,发现运行页面表现正常,但是控制台报如下错误:

 1 Unable to simultaneously satisfy constraints.
 2     Probably at least one of the constraints in the following list is one you don't want. 
 3     Try this: 
 4         (1) look at each constraint and try to figure out which you don't expect; 
 5         (2) find the code that added the unwanted constraint or constraints and fix it. 
 6 (
 7     <NSLayoutConstraint:0x10c30ee10 V:[UILabel:0x10c30ebb0'Label'(21.6667)]>,
 8     <NSLayoutConstraint:0x10c30f9c0 V:[UIView:0x10c30ea20(0)]>,
 9     <NSLayoutConstraint:0x10c30fab0 V:|-(0)-[UILabel:0x10c30ebb0'Label']   (Names: '|':UIView:0x10c30ea20 )>,
10     <NSLayoutConstraint:0x10c30fb00 V:[UILabel:0x10c30ebb0'Label']-(0)-[UILabel:0x10c30f080'Label']>,
11     <NSLayoutConstraint:0x10c30fb50 UILabel:0x10c30f080'Label'.height == UILabel:0x10c30ebb0'Label'.height>,
12     <NSLayoutConstraint:0x10c30fc90 V:[UILabel:0x10c30f3d0'Label']-(0)-|   (Names: '|':UIView:0x10c30ea20 )>,
13     <NSLayoutConstraint:0x10c30fd80 V:[UILabel:0x10c30f080'Label']-(0)-[UILabel:0x10c30f3d0'Label']>
14 )
15 
16 
17 Will attempt to recover by breaking constraint 
18 <NSLayoutConstraint:0x10c30ee10 V:[UILabel:0x10c30ebb0'Label'(21.6667)]>
19 
20 Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
21 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中设置的高度约束与代码中更新的高度约束不一致时,

取代码中设置的值。

原文地址:https://www.cnblogs.com/china-fanny/p/7240347.html