gpt4 book ai didi

ios - 如何在 iOS 11 中隐藏章节标题?

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:24 25 4
gpt4 key购买 nike

在 iOS 11 中,无论项目是 0 还是更多,我的部分标题总是会出现。

在 iOS 10 设备上,当项目计数为 0 时,我的代码有效并且部分消失。但在 iOS 11 上,相同的代码没有影响。

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if sections[section].items.count > 0{
return sections[section].title
}else{
return nil
}
}

最佳答案

在 iOS 11 中,如果您只实现 titleForHeaderInSection 并返回 nil,您将看不到标题 View 。但是如果你也实现了viewForHeaderInSection,不管你返回什么,都会有一个section。

仅此一项不会显示节标题:

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return nil
}

这将显示一个没有标题的节标题:

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return nil
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}

因此这两种方法都可能返回 nil 并且 header 将可见。如果仅实现 titleForHeaderInSection,则不会显示标题。这似乎只在 iOS 11 中存在。不确定这是一个错误还是一种强制开发人员选择两种方法的方法。但是文档确认了关于 titleForHeaderInSection 的这种行为:

"Return Value: A string to use as the title of the section header. If you return nil , the section will have no title."

因此与显示或不显示无关,此方法仅返回标题的字符串。这是有道理的。但是看起来像错误的是,在 viewForHeaderInSection 中返回 nil 将显示节标题。

关于ios - 如何在 iOS 11 中隐藏章节标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46594585/

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