swift - swift中tableview单元格的自动布局错误
问题描述
我正在使用 UITableViewCell 的自动布局并出现以下错误。我该如何解决?
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.
解决方案
如果您正在设置 ImageView 的高度,则无需设置底部约束甚至顶部约束。删除底部和顶部约束并将约束添加到 centerY 即垂直居中图像视图到容器。
您遇到此问题的原因是因为它不明确满足哪个约束是图像视图的高度约束还是顶部/底部约束。
推荐阅读
- r - 在R中的数据框中移动值
- c# - WPF 中的脱机图像缓存
- apache-camel - 具有LIFO排序的Apache Camel SEDA队列?
- javascript - 如何在 html 中为 html2canvas 打印标签图像
- python - 选择熊猫数据框中的一些列
- python - TypeError:参数 1 必须是 pygame.Surface,而不是 MyClass
- c++ - 如何在 Fedora 27 上仅安装和使用 Clang-Format?
- vba - Word VBA:删除段落标记
- javascript - 有没有办法将数据属性添加到 codemirror 行?
- python - 新样式 getargs 格式,但参数不是元组错误调用洪水填充