我有表格单元格,根据标签文字大小动态调整其高度。我还通过使它们的高度为0来使一些细胞不可见。
在viewDidLoad中:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 70
然后:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let item = datasource[indexPath.row]
if item.isVisible == true {
return UITableViewAutomaticDimension
}
else{
return 0
}
}
在uitableviewcell的内容视图中,我在其下方有标签和文本字段。像这样:
=====================
TopHeightToSuperview
的UILabel
BottomSpaceToTextField
的UITextField
BottomSpaceToSuperview
=====================
细胞正确调整大小。但是我收到了这个错误:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd05ded2150 V:[TitleLabel(17)] (Names: TitleLabel:0x7fd05ded0760 )>
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.
2016-06-29 17:24:03.391 invest.comQA[98164:6141441] 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:0x7fd05deed120 V:|-(15)-[TitleLabel] (Names: TitleLabel:0x7fd05ded0760, '|':UITableViewCellContentView:0x7fd05dee8000 )>",
"<NSLayoutConstraint:0x7fd05deed260 V:[Text Field]-(14)-| (Names: Text Field:0x7fd05deea9a0, '|':UITableViewCellContentView:0x7fd05dee8000 )>",
"<NSLayoutConstraint:0x7fd05deed420 V:[TitleLabel]-(15)-[Text Field] (Names: Text Field:0x7fd05deea9a0, TitleLabel:0x7fd05ded0760 )>",
"<NSLayoutConstraint:0x7fd05def1f00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fd05dee8000(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd05deed420 V:[TitleLabel]-(15)-[Text Field] (Names: Text Field:0x7fd05deea9a0, TitleLabel:0x7fd05ded0760 )>
为什么?