ios - 删除节标题和 uitableviewcell 之间的分隔符

标签 ios uitableview

如何去除图片中指示的线条?我尝试了以下建议,但没有一个对我有用,

How do I remove the borders of a UITableView?

Remove separator line for only one cell

Hide separator line on one UITableViewCell

这是我当前在 cellForRowAt 中的代码:

       if (indexPath.row == place_sections[indexPath.section].rows.count - 1) {
            cell.separatorInset.left = 1000
            //cell.layer.borderWidth = 0
            //cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);

        }
        if (indexPath.row == 0) {
            cell.separatorInset.left = 1000
            //cell.layer.borderWidth = 0
            //cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);

            //                self.tableview.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableview.frame.width, height: 1))
        }

谢谢

enter image description here

最佳答案

标题和单元格之间的分隔符属于节中的第一个单元格。 当我使用标准的 UITableViewHeaderFooterViewUITableViewCell 时,我设法通过以下代码隐藏了页眉和单元格之间的线:

let contentView = cell.contentView
if
    // this separator is subview of first UITableViewCell in section
    indexPath.row == 0,
    // truing to find it in subviews
    let divider = cell.subviews.filter({ $0.frame.minY == 0 && $0 !== contentView }).first
{
    divider.isHidden = true
}

这段代码必须在tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

中调用

关于ios - 删除节标题和 uitableviewcell 之间的分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48199381/

相关文章:

ios - UISegmentedControl 段顺序困惑

ios - 如何在运行时 Objective-C 中重写/混合私有(private)类的方法?

cocoa-touch - 使用通知中心重新加载 UITableView 可以吗?

为 UiTableview 安排多个操作的 iOS 最佳实践

iphone - 删除 UITableView 中的行分隔符但不删除边框

ios - SwiftUI |阻止 TextField 自动随键盘向上移动

objective-c - UITableView 正在填充整个 View

ios - UITableViewCell Z 顺序

ios - 核心数据 : no index path for table cell being reused, 单元格消失

ios - 更新到 Xcode 9 后 UITableView 中的布局问题