如何删除 UITableView 部分标题分隔符 [英] How to remove UITableView section header separator
问题描述
我想删除(或使它们 clearColor)UITableView 的部分标题分隔符.设置 tableView.separatorStyle = .none
不起作用.我也尝试过这里的解决方案,但没有一个真正适用我(也许是因为答案很旧).我仍然在节标题下方看到这个小分隔符.
I would like to remove (or make them clearColor) UITableView's section header separators. Setting tableView.separatorStyle = .none
doesn't work. I've also tried solutions from here, but none of them actually worked for me (maybe because the answers are pretty old). I still get this tiny separator below the section header.
我在 Storyboard 中创建了 UITableView 并在那里添加了一个 UITableViewCell.然后我将它设置为这样的标题:
I created the UITableView in Storyboard and add a UITableViewCell there. Then I set it as a header like this:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "headerTableViewCell")
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 1 {
return 49
}
return 0
}
推荐答案
不知道你为什么在 viewForHeaderInSection
方法中返回 UITableViewCell
所以可能有可能显示 UITableViewCell
的分隔符.尝试从 viewForHeaderInSection
方法返回单元格的 contentView
而不是单元格.
Don't know why you are returning UITableViewCell
in viewForHeaderInSection
method so may be it is possible that is showing separator of that UITableViewCell
. Try returning the contentView
of cell instead of cell from viewForHeaderInSection
method.
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "headerTableViewCell")
return cell.contentView
}
这篇关于如何删除 UITableView 部分标题分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!