重新排序 UITableViewCell 时出现 NSLayoutConstrains 错误

NSLayoutConstrains error occurs when reorder the UITableViewCell

我在故事板中设置了一个简单的单元格,

这是一个imageview和一个label,我设置了一些约束,imageView的leading,top和bottom space到contentview,imageView的width和height,label的水平间距到imageview,垂直居中到图片视图。 当我 运行 应用程序时,它显示正确,没有错误发生。

右边的BarButtonItem是系统编辑按钮。当我重新排序单元格时,出现约束错误,我不知道如何修复它。

2015-11-11 23:08:05.681 HiPDA[10108:2305919] 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:0x7fce60ce6cf0 V:[UIImageView:0x7fce60cac370(40)]>",
"<NSLayoutConstraint:0x7fce60ce6f10 UITableViewCellContentView:0x7fce60ca0610.topMargin == UIImageView:0x7fce60cac370.top>",
"<NSLayoutConstraint:0x7fce60ce7020 UITableViewCellContentView:0x7fce60ca0610.bottomMargin == UIImageView:0x7fce60cac370.bottom - 0.5>",
"<NSLayoutConstraint:0x7fce60c03a70 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fce60ca0610(56)]>"
)

Will attempt to recover by breaking constraint 

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.

我很困惑,当它显示,滚动和删除时,没有发生错误,但是当我重新排序单元格时,发生约束错误,我不知道如何解决。谢谢。

我上传了工程,你可以在这里下载download link

有两个navigation controller,更改它们之间的init controller,当tableviewcell只包含label时不报错,但当tableviewcell包含imageview时reorder cell时报错

看看你的约束,冲突是

imageview 高度设置为 40,它固定在单元格的顶部和底部,而单元格高度为 56。您想要 imageview 40 还是 56 多大?

您可以通过删除顶部和底部约束来解决这个问题,只需对单元格约束做一个垂直中心。即 ImageView.centerY = centerY

这里是您的项目在图像视图上的修改约束

你给了 imageView 两组约束来确定它的高度,一个是顶部&&底部space,另一个是高度。

当它们相互冲突时,你会得到这个alert.Change其中一个是可选的将解决问题。

在您的情况下,您可以将 imageView 的高度约束从“=”更改为“>=”,或者将较低的高度约束的优先级更改为 999。