用xib自定义cell时,给label的添加约束:(top:10, leading:10, trailing:10, height:10)
注:label设置numberOfLines = 0, 多行显示的.
问题:
当用代码修改height的约束时,报下面的错.
不用代码修改height的约束时, 错误消失.???
解决方法:
删除height的约束,label会自适应,label的高度可以计算出来,用boundingRectWithSize
然后计算出cell的高度.
错误信息:
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.
(
"<NSLayoutConstraint:0x7d1b1630 UIImageView:0x7d1b1520.height == 40>"
"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"
"<NSLayoutConstraint:0x7d1b0cc0 UIImageView:0x7d1b0bb0.height == 20>"
"<NSLayoutConstraint:0x7d1b1bc0 UIButton:0x7d1b1a60.height == 30>"
"<NSLayoutConstraint:0x7d1b1000 UIImageView:0x7d1b0f20.height == 1>"
"<NSLayoutConstraint:0x7d1bccb0 UIImageView:0x7d1b1520.top == UITableViewCellContentView:0x7d1b1420.top + 5>"
"<NSLayoutConstraint:0x7d1bcd40 UILabel:0x7d1b0920.top == UIImageView:0x7d1b1520.bottom + 10>"
"<NSLayoutConstraint:0x7d1bd350 UIView:0x7d1bc7d0.top == UILabel:0x7d1b0920.bottom + 10>"
"<NSLayoutConstraint:0x7d1bd470 UIImageView:0x7d1b0f20.top == UIView:0x7d1bc7d0.bottom + 10>"
"<NSLayoutConstraint:0x7d1be6c0 UIButton:0x7d1b1a60.top == UIImageView:0x7d1b0f20.bottom>"
"<NSLayoutConstraint:0x7d1be6f0 UITableViewCellContentView:0x7d1b1420.bottom == UIImageView:0x7d1b0bb0.bottom>"
"<NSLayoutConstraint:0x7d1be720 UIImageView:0x7d1b0bb0.top == UIButton:0x7d1b1a60.bottom>"
"<NSLayoutConstraint:0x7d75eb20 UITableViewCellContentView:0x7d1b1420.height == 217.375>"
)
Will attempt to recover by breaking constraint
"<NSLayoutConstraint:0x7d1bb780 UILabel:0x7d1b0920.height == 225.031>"
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.