这是我的布局:
问题是关于第二个自定义单元。我有一个UIImageView和一个UILabel。我想在单元格的左侧对齐图像,并用标签填充其他可用空间。
我已经录制了一个GIF动画来向您展示该过程:
结果正常。但是然后我想为我的自定义单元选择“细节附件”选项。
之后,我得到这个:
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/