用xib自定義cell時(shí),給label的添加約束:(top:10,? leading:10,? trailing:10,? height:10)
注:label設(shè)置numberOfLines = 0, 多行顯示的.
問題:
當(dāng)用代碼修改height的約束時(shí),報(bào)下面的錯(cuò).
不用代碼修改height的約束時(shí), 錯(cuò)誤消失.???
解決方法:
刪除height的約束,label會(huì)自適應(yīng),label的高度可以計(jì)算出來,用boundingRectWithSize
然后計(jì)算出cell的高度.
錯(cuò)誤信息:
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.