Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the separator between section header & uitableviewcell

Tags:

How do I remove the lines indicated in the picture? I have tried the following suggestions and none of them have worked for me,

How do I remove the borders of a UITableView?

Remove separator line for only one cell

Hide separator line on one UITableViewCell

This is my current code in 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))
        }

Thank you

enter image description here

like image 408
degenPenguin Avatar asked Jan 11 '18 03:01

degenPenguin


1 Answers

Separator between header and cell belongs to first cell in section. When I used standard UITableViewHeaderFooterView and UITableViewCell I managed to hide line between header and cell via this code:

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
}

This piece of code must be invoked in tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

like image 90
Konstantin Berkov Avatar answered Oct 13 '22 00:10

Konstantin Berkov