我的应用程序中有一个UITableView。它填充了一个名为Lesson Cell的Custom UITableCell。它看起来像http://i.imgur.com/VoCxkJa.png
每当此视图加载时它显示了一堆布局错误,如下所示。但我的Interface Builder
看起来很好。我研究过&尝试了很多来解决这个错误。
请帮帮我。在此先感谢
2015-08-17 12:25:51.543 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7f85706d4150 UILabel:0x7f85706eb5c0'How Old are You?'.leading == UITableViewCellContentView:0x7f85706ce730.leadingMargin + 8>",
"<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>",
"<NSLayoutConstraint:0x7f85706e7710 'fittingSizeHTarget' H:[UITableViewCellContentView:0x7f85706ce730(34)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>
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.
修改
我在View Controller中使用Dynamic Table View Cell。可能是这个原因有什么问题吗?
LessonTable.estimatedRowHeight = 120
LessonTable.rowHeight = UITableViewAutomaticDimension
答案 0 :(得分:0)
UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>
存在约束冲突,以便为您的案例轻松修复,只需为拥抱UILabel添加优先级。
来自代码:
[urLabelCell setContentHuggingPriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
[urLabelCell setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[urLabelCell setContentCompressionResistancePriority:UILayoutPriorityFittingSizeLevel forAxis:UILayoutConstraintAxisHorizontal];
[urLabelCell setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
或在IB中:
并且基本上删除了这个规则之一:
"<NSLayoutConstraint:0x7f85706d4150 UILabel:0x7f85706eb5c0'How Old are You?'.leading == UITableViewCellContentView:0x7f85706ce730.leadingMargin + 8>",
"<NSLayoutConstraint:0x7f85706c6450 UITableViewCellContentView:0x7f85706ce730.trailingMargin == UILabel:0x7f85706eb5c0'How Old are You?'.trailing + 50>",
或设置不同的优先级