gpt4 book ai didi

ios - 如何在 UITableView [Swift] 中设置特定的节标题

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

我想以编程方式将节标题添加到我的 UITableView 的节中。

我正在尝试使用此代码,但它会将标题添加到所有部分。我怎样才能让它只设置第一部分的标题?

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "My Section header"
}

最佳答案

使用 switch-case 可以写出更好的代码

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0: return "Section 0"
case 1: return "Section 1"
default: return nil
}
}

关于ios - 如何在 UITableView [Swift] 中设置特定的节标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54017345/

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