gpt4 book ai didi

ios - 标题 View 模型

转载 作者:行者123 更新时间:2023-12-01 16:05:30 27 4
gpt4 key购买 nike

表中有 5 个部分。除了第一个和第二个部分之外的所有部分都有一个 View 标题。这个 View 是使用 xib 制作的。它有一个标签和一个按钮。在每个部分中,此标签和按钮都会更改文本。我该如何实现呢?我在单独的文件中设置了这个快捷方式和按钮的文本。但是我不明白如何在每个部分中显示相应的文本。

 enum header: Int, CaseIterable {

case oneSection
case twoSection
case thirdSection
case fourthSection
case fifthSection

var title:String {
switch self {
case .oneSection:
return ""
case .twoSection:
return ""
case .thirdSection:
return "thirdSection"
case .fourthSection:
return "fourthSection"
case .fifthSection:
return "fifthSection"
}
}
}

最佳答案

您可以使用 viewForHeaderInSection为此的委托(delegate)方法:

enum header: Int, CaseIterable {
case oneSection = 0
case twoSection
case thirdSection
case fourthSection
case fifthSection
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

let view = // load your view here from the xib

switch section {
case .thirdSection:
view.label = "thirdSection"

case .fourthSection:
view.label = "fourthSection"

case .fifthSection:
view.label = "fifthSection"

default:
break
}

return view
}

关于ios - 标题 View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62004114/

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