gpt4 book ai didi

swift - 折叠 Tableview 部分时出现约束错误

转载 作者:行者123 更新时间:2023-11-28 07:32:39 26 4
gpt4 key购买 nike

我有一个自定义单元格 View ,其中包含嵌入在垂直堆栈 View 中的图像和标签。

堆栈 View 绑定(bind)到内容 View 的 4 个边缘。

图像有 1:1 纵横比的约束。

展开和折叠操作似乎工作正常,但是当我继续点击时,我在某些时候看到了一些警告,这似乎是随机的。

cell preview expanded row

2019-01-17 23:15:46.749683+0300 MyApp[10270:349316] [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:0x6000032e54a0 UIStackView:0x7f9f97d19620.height == 43.5 (active)>",
"<NSLayoutConstraint:0x6000032e5590 V:[UIStackView:0x7f9f97d19620]-(5)-| (active, names: '|':UITableViewCellContentView:0x7f9f97d19430 )>",
"<NSLayoutConstraint:0x6000032e5630 V:|-(5)-[UIStackView:0x7f9f97d19620] (active, names: '|':UITableViewCellContentView:0x7f9f97d19430 )>",
"<NSLayoutConstraint:0x6000032e5f40 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f9f97d19430.height == 499.5 (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000032e54a0 UIStackView:0x7f9f97d19620.height == 43.5 (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.

我运行展开/折叠的内容如下:

....
tableView.register(UINib(nibName: "InboxTableViewCell", bundle: nil), forCellReuseIdentifier: "inboxCell")
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 500
tableView.reloadData()
....

func numberOfSections(in tableView: UITableView) -> Int {
return tableViewData.count
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

if tableViewData[section].opened == true {
return tableViewData[section].sectionData.count + 1
}else {
return 1
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {

let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell", for: indexPath) as! HeaderTableViewCell
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "inboxCell", for: indexPath) as! InboxTableViewCell

return cell
}
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0{
if tableViewData[indexPath.section].opened == true {
tableViewData[indexPath.section].opened = false
let sections = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(sections, with: .none)

}else{
tableViewData[indexPath.section].opened = true
let sections = IndexSet.init(integer: indexPath.section)
tableView.reloadSections(sections, with: .none)

}
}
}

最佳答案

将图像的 1:1 纵横比约束的优先级设置为 999 或更低。它强制自动布局为堆栈 View 生成高度约束以维持纵横比。这对业务不利。

关于swift - 折叠 Tableview 部分时出现约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54243811/

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