ios - 如何删除 UITableView 部分标题分隔符

标签 ios swift uitableview storyboard

我想删除(或使它们为 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/

相关文章:

ios - 架构 armv7 错误的重复符号

ios - TableView 自定义单元格未根据约束做出响应

ios - UISearchDisplayController 在没有结果时显示自定义 UITableViewCell

ios - 如何使节点与移动场景的侧面发生碰撞?

ios - 如何让视频在我的视频选择 Controller 中播放

swift - 如果使用导航 Controller Swift,如何用键盘向上移动 UITextField

iphone - 自定义单元格被其他单元格替换

objective-c - iOS SDK,Objective-C,仅可显示一个单元格

ios - 使用 CGLayerRef 和 CGContextDrawLayerInRect mask 图像

ios - 共享 iAd 横幅