'How to remove section header separator in iOS 15

In iOS 15, UITableView adds a separator between a section header and the first cell:

enter image description here

How can I hide or remove that separator?

A few notes:

  1. The header is a custom view returned from tableView(_:viewForHeaderInSection:).
  2. When looking at the view debugger, I can see that the extra separator is actually a subview of the first cell, which now has a top and a bottom separator.
  3. Other than setting tableView.separatorInset to change the inset of cell separators, this is a completely standard table view with no customizations.


Solution 1:[1]

I had a similar issue, but it was due to the table header view suddenly showing as a separator on iOS 15. The only thing that worked for me was:

if #available(iOS 15.0, *)
{
    tableView.tableHeaderView = UIView()
}

Solution 2:[2]

iOS 15, Swift 5

To remove the line between the section header and your first cell, you should set sectionHeaderTopPadding to zero while configuring your UITableView.

    if #available(iOS 15.0, *) {
        tableView.sectionHeaderTopPadding = 0.0
    }

Solution 3:[3]

I believe tableView.separatorStyle = .none should do the trick.

Solution 4:[4]

I was able to fix it with this code.

if (@available(iOS 15.0, *)) {
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    [self.tableView setSectionHeaderTopPadding:0.0f];
}

Solution 5:[5]

In my case I wanted to use the native section header and the top padding different than 0, so this should work if you want to remove the extra top and bottom separators on each section:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // Dequeue cell and set it up ...
    if indexPath.row == 0 {
        let separator = cell.subviews.filter({
            $0.frame.minY == 0 && $0 !== cell.contentView
        }).first
        separator?.isHidden = true
        cell.separatorInset.left = 0 // Or whatever desired inset
    }
    if indexPath.row + 1 == dataSource[indexPath.section].count {
        cell.separatorInset.left = cell.bounds.width
    } else {
        cell.separatorInset.left = 0 // Or whatever desired inset
    }
    return cell
}

Solution 6:[6]

There can be two solutions to your problem/

  1. One is

    self.tableView.separatorColor = self.tableView.backgroundColor

this is a trick solution, it makes outer lines "disappear" and keep separator lines visible

  1. second is

change your tableview type from grouped to plain if grouping not used.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivan Andriollo
Solution 2 Sajjad Sarkoobi
Solution 3 Solomiya
Solution 4 Osamu
Solution 5 Lautaro de los Heros
Solution 6 Abu Ul Hassan