gpt4 book ai didi

ios - UITableViewHeaderFooterView 上的约束导致 UIViewAlertForUnsatisfiableConstraints

转载 作者:搜寻专家 更新时间:2023-11-01 07:07:35 24 4
gpt4 key购买 nike

现在一直茫然地盯着这个看,可能太久了,所以我在这里尝试发帖。

这是我看到的错误:

2017-11-02 22:43:23.972361-0700 TableViewCellHeaderViewLayoutTest[88247:17250641] [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:0x60c000092930 V:|-(12)-[UILabel:0x7fd450c0eb80'Header 1'] (active, names: '|':_UITableViewHeaderFooterContentView:0x7fd450c0f290 )>",
"<NSLayoutConstraint:0x60c0000927f0 UILabel:0x7fd450c0eb80'Header 1'.bottom == _UITableViewHeaderFooterContentView:0x7fd450c0f290.bottom - 6 (active)>",
"<NSLayoutConstraint:0x60c000092ac0 'UIView-Encapsulated-Layout-Height' _UITableViewHeaderFooterContentView:0x7fd450c0f290.height == 17.5 (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c0000927f0 UILabel:0x7fd450c0eb80'Header 1'.bottom == _UITableViewHeaderFooterContentView:0x7fd450c0f290.bottom - 6 (active)>

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.

这是我的 UITableViewHeaderFooterView 子类的 super 简单实现:

class TableViewSectionHeaderView: UITableViewHeaderFooterView {

let titleLabel = UILabel()

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)

contentView.backgroundColor = .gray

titleLabel.backgroundColor = contentView.backgroundColor
titleLabel.font = UIFont.preferredFont(forTextStyle: .footnote)

contentView.addSubview(titleLabel)

titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 12).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 6).isActive = true
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -6).isActive = true
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -6).isActive = true
}

}

对我来说最突出的是这个约束:

"<NSLayoutConstraint:0x60c000092ac0 'UIView-Encapsulated-Layout-Height' _UITableViewHeaderFooterContentView:0x7fd450c0f290.height == 17.5   (active)>"

如果我检查它,它也有 1000priority,这解释了为什么我自己的约束似乎失败了。

一切在视觉上都很好,但我担心那个警告。我做错了什么?

最佳答案

看起来部分标题高度与标签的顶部和底部约束以及实际标签的固有高度竞争。部分标题可能需要根据标签的高度增大或缩小,但严格的标题高度限制会导致冲突。

将 sectionHeaderHeight 和 estimatedSectionHeaderHeight 设置为 UITableViewAutomaticDimension 以允许根据部分的内容(在本例中为标签)调整高度。

关于ios - UITableViewHeaderFooterView 上的约束导致 UIViewAlertForUnsatisfiableConstraints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47089241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com