Ios 无法同时满足动态单元的高度约束
我有表格单元格,根据标签文本大小动态调整其高度。我还通过使某些单元格的高度为0,使其不可见 在viewDidLoad中:Ios 无法同时满足动态单元的高度约束,ios,swift,Ios,Swift,我有表格单元格,根据标签文本大小动态调整其高度。我还通过使某些单元格的高度为0,使其不可见 在viewDidLoad中: tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 70 然后: func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGF
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的内容视图中,我在其下方有标签和文本字段。像这样:
=====================
最高高度至最高高度
UILabel
BottomSpaceToTextField
UITextField
底部空间监视
=====================
单元格正在正确调整大小。但我收到了这个错误:
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 )>
将尝试通过破坏约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建一个符号断点,以便在调试器中捕获该断点。
中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助。
2016-06-29 17:24:03.391投资。comQA[98164:6141441]无法同时满足约束条件。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
为什么?尝试清除约束,然后添加缺少的约束。这似乎神奇地解决了我的问题