gpt4 book ai didi

ios - 如何在 TableView cellForRow 委托(delegate)方法中隐藏堆栈 View 中的 View

转载 作者:行者123 更新时间:2023-11-28 06:16:29 24 4
gpt4 key购买 nike

如果我的数据模型中的某个属性为 nil,我想知道从堆栈 View 中删除 View 的最简洁方法是什么。我有一个由原型(prototype)单元格填充的 TableView 。它们看起来像这样:

enter image description here

第二个标签文本包含一个可选值,可以是nil;如果标签为零,我想隐藏它。我应该在 cellForRow TableView 单元格方法中调用 removeArrangedSubview 还是在带有函数的 CustomTableViewCell 类中调用?

最佳答案

I want to hide the label if [optional value] is nil

您应该将标签的 hidden 属性设置为 true 而不是将其从堆栈布局的已排列 subview 列表中删除,以避免在单元格被重复使用时将其添加回来不同的行。

这主要取决于您在哪里操作。如果您的大部分单元格设置代码都在 cellForRow 函数中,您还应该隐藏和取消隐藏该函数中的标签:

if let labelText = model.getTextForMyLabel(indexPath.row) {
cell.label.text = labelText
cell.label.hidden = false
} else {
cell.label.hidden = true
}

如果您的 CustomTableViewCell 代码中有标签文本 setter ,您可以使用相同的方法来设置标签的 hidden 属性及其 文字.

关于ios - 如何在 TableView cellForRow 委托(delegate)方法中隐藏堆栈 View 中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44984516/

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