首页 > 解决方案 > swift中tableview单元格的自动布局错误

问题描述

我正在使用 UITableViewCell 的自动布局并出现以下错误。我该如何解决?

1

2

2020-09-15 11:42:13.104796+0900 heart-to-heart[14602:1800620] [LayoutConstraints] 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:0x6000022eb890 UIImageView:0x7fdd1f01efc0.height == 50   (active)>",
    "<NSLayoutConstraint:0x6000022c7480 V:|-(16)-[UIImageView:0x7fdd1f01efc0]   (active, names: '|':UITableViewCellContentView:0x7fdd1f01eb00 )>",
    "<NSLayoutConstraint:0x6000022c74d0 V:[UIImageView:0x7fdd1f01efc0]-(16)-|   (active, names: '|':UITableViewCellContentView:0x7fdd1f01eb00 )>",
    "<NSLayoutConstraint:0x6000022c1d10 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fdd1f01eb00.height == 82.3333   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000022eb890 UIImageView:0x7fdd1f01efc0.height == 50   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

标签: swiftautolayout

解决方案


如果您正在设置 ImageView 的高度,则无需设置底部约束甚至顶部约束。删除底部和顶部约束并将约束添加到 centerY 即垂直居中图像视图到容器。

您遇到此问题的原因是因为它不明确满足哪个约束是图像视图的高度约束还是顶部/底部约束。


推荐阅读