gpt4 book ai didi

ios - 带有 UITableViewAutomaticDimension 的 UITableViewCell rowHeight 不适用于计算自动布局

转载 作者:行者123 更新时间:2023-11-28 15:08:22 25 4
gpt4 key购买 nike

我有 UITableViewCell,其中多个组件充当行,由 UIView 中的 UILabel、UIView 和 UIStackView 的混合元素组成。

enter image description here

单元格内的每个组件都有高度限制。我希望通过在运行时将高度约束的常量设置为零或 21 来使单元格的高度动态变化,这取决于它是否有要显示的内容。

// more codes like below    
if let mealPref = passenger.mealPref {
mealPrefHeight.constant = 21
let title = R.string.localizable.meal_request.localized()
mealPrefLabel.text = "• \(title): \(mealPref)"
} else {
mealPrefHeight.constant = 0
}
// more codes like above

它不起作用。

我有类似的problem back then ,但我认为情况不同。我读过 this , thisthis .

enter image description here

enter image description here

最佳答案

你在viewDidLoad中添加了吗

tableView.estimatedRowHeight = 44 // for assumption
tableView.rowHeight = UITableViewAutomaticDimension

关于ios - 带有 UITableViewAutomaticDimension 的 UITableViewCell rowHeight 不适用于计算自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48070964/

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