ios - 简单自定义 UITableViewCell 的自动布局错误

标签 ios objective-c xcode uitableview autolayout

这是我的布局:

enter image description here

问题是关于第二个自定义单元格。我有一个 UIImageView 和一个 UILabel。我想让图像在单元格左侧对齐,标签填充其他可用空间。

我录制了一个 GIF 动画来向您展示整个过程:

enter image description here

结果是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。

解决这个问题的方法是:

  1. 移除约束:fileIcon 的底部和顶部约束。
  2. 添加约束:在容器中垂直居中

关于ios - 简单自定义 UITableViewCell 的自动布局错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607869/

相关文章:

ios - CLLocation altitude 属性在飞行中的有效性

asp.net - IOS 上无服务器多人游戏

ios - NSURLAuthenticationChallenge.sender 返回 nil

iphone - 如何以编程方式使 UIToolbar 覆盖?

iOS自定义形状导航栏

ios - 将来自 parse.com 的数据保存在字符串中的问题

ios - 在保存到 coredata -Swift 之前检查数据是否存在

iphone - 如何使用核心图更改部分散点图的线条颜色?

objective-c - 有谁知道如何将cv::Mat转换为NSString?

xcode - 核心数据错误: "Can' t find model for source store"