这是我的布局:
问题是关于第二个自定义单元格。我有一个 UIImageView 和一个 UILabel。我想让图像在单元格左侧对齐,标签填充其他可用空间。
我录制了一个 GIF 动画来向您展示整个过程:
结果是OK的。但后来我想为我的自定义单元选择“详细附件”选项。
之后我得到了这个:
2016-09-21 11:23:57.976 ODFileManager2[4861:70193] 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:0x7fe62addd190 H:[fileIcon(43)] (Names: fileIcon:0x7fe62addcfc0 )>",
"<NSLayoutConstraint:0x7fe62addf1b0 fileIcon.leading == UITableViewCellContentView:0x7fe62addc2c0.leadingMargin (Names: fileIcon:0x7fe62addcfc0 )>",
"<NSLayoutConstraint:0x7fe62addf340 H:[fileIcon]-(0)-[UILabel:0x7fe62addc7d0'Label'] (Names: fileIcon:0x7fe62addcfc0 )>",
"<NSLayoutConstraint:0x7fe62addf390 UITableViewCellContentView:0x7fe62addc2c0.trailingMargin == UILabel:0x7fe62addc7d0'Label'.trailing>",
"<NSLayoutConstraint:0x7fe62ade5e20 'fittingSizeHTarget' H:[UITableViewCellContentView:0x7fe62addc2c0(48)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe62addd190 H:[fileIcon(43)] (Names: fileIcon:0x7fe62addcfc0 )>
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.
尽管一切看起来仍然不错。
最佳答案
高度有问题,你设置了43,但是单元格高度是48。
解决这个问题的方法是:
- 移除约束:
fileIcon
的底部和顶部约束。 - 添加约束:在容器中垂直居中
关于ios - 简单自定义 UITableViewCell 的自动布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607869/