我想删除(或使它们为 clearColor)UITableView 的节标题分隔符。设置 tableView.separatorStyle = .none
不起作用。我也尝试过 here 的解决方案,但实际上没有一个对我有用(可能是因为答案很旧)。我仍然在节标题下方看到这个小分隔符。
我在 Storyboard 中创建了 UITableView 并在其中添加了一个 UITableViewCell。然后我将它设置为这样的标题:
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
而不是单元格。
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "headerTableViewCell")
return cell.contentView
}
关于ios - 如何删除 UITableView 部分标题分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42296265/