如何修复 TableViewCell 约束冲突?
Posted
技术标签:
【中文标题】如何修复 TableViewCell 约束冲突?【英文标题】:How to fix TableViewCell constraints conflict? 【发布时间】:2020-01-29 05:18:24 【问题描述】:在某些表格单元格动画期间,由于某种原因,左圆形按钮开始破坏自动布局
我在日志中收到以下错误
2020-01-28 22:09:56.581680-0500 Zenn[19786:13017249] [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:0x600000122670 UIButton:0x7f92b3c10520'Button'.height == 30 (active)>",
"<NSLayoutConstraint:0x60000012d900 V:[UIStackView:0x7f92b3c18670]-(10)-| (active, names: '|':UITableViewCellContentView:0x7f92b3c18cd0 )>",
"<NSLayoutConstraint:0x60000012d810 V:|-(10)-[UIStackView:0x7f92b3c18670] (active, names: '|':UITableViewCellContentView:0x7f92b3c18cd0 )>",
"<NSLayoutConstraint:0x60000012eda0 'UISV-canvas-connection' UIStackView:0x7f92b3c1a970.top == UIButton:0x7f92b3c10520'Button'.top (active)>",
"<NSLayoutConstraint:0x60000012edf0 'UISV-canvas-connection' V:[UIButton:0x7f92b3c10520'Button']-(0)-| (active, names: '|':UIStackView:0x7f92b3c1a970 )>",
"<NSLayoutConstraint:0x60000012f1b0 'UISV-canvas-connection' UILayoutGuide:0x600001b17480'UIViewLayoutMarginsGuide'.top == Zenn.UITextViewCustom:0x7f92b4050c00'Www.google.com \n\n64768695...'.top (active)>",
"<NSLayoutConstraint:0x60000012f200 'UISV-canvas-connection' UILayoutGuide:0x600001b17480'UIViewLayoutMarginsGuide'.bottom == Zenn.UITextViewCustom:0x7f92b4050c00'Www.google.com \n\n64768695...'.bottom (active)>",
"<NSLayoutConstraint:0x60000012f250 'UISV-canvas-connection' UIStackView:0x7f92b3c18670.top == UIStackView:0x7f92b3c1a970.top (active)>",
"<NSLayoutConstraint:0x60000012fac0 'UISV-canvas-connection' V:[UIStackView:0x7f92b3c1d0b0]-(0)-| (active, names: '|':UIStackView:0x7f92b3c18670 )>",
"<NSLayoutConstraint:0x600000128050 'UISV-spacing' V:[UIStackView:0x7f92b3c1a970]-(0)-[UIStackView:0x7f92b3c1d0b0] (active)>",
"<NSLayoutConstraint:0x60000012efd0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x600001b17480'UIViewLayoutMarginsGuide']-(8)-| (active, names: '|':UIStackView:0x7f92b3c1d0b0 )>",
"<NSLayoutConstraint:0x600000139c20 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f92b3c18cd0.height == 50 (active)>",
"<NSLayoutConstraint:0x60000012ef30 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x600001b17480'UIViewLayoutMarginsGuide'] (active, names: '|':UIStackView:0x7f92b3c1d0b0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000122670 UIButton:0x7f92b3c10520'Button'.height == 30 (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.
好像已经不能满足按钮高度设置为30的要求了,但是有什么冲突呢?
【问题讨论】:
你在stackview里面设置了单选按钮吗? 这些是随故事板添加的,还是程序化创建的? 这些是与故事板一起添加的 没有单选按钮,只有 UIButton(左侧圆圈)和 UITextField @erotsppa 我的意思是你已经在 UIStackView 中添加了所有子视图? 【参考方案1】:仔细检查您的约束并为 tableViewCell 高度添加委托方法。
斯威夫特 5
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
return UITableView.automaticDimension
【讨论】:
以上是关于如何修复 TableViewCell 约束冲突?的主要内容,如果未能解决你的问题,请参考以下文章
iOS:如何在其附件视图更改时触发 tableViewCell 的约束/自动布局刷新?
如何修复“MySQL 错误:1822。缺少约束索引”关于创建复合外键
swift - 快速按下集合视图单元格时如何修复自定义视图中的约束