How to hide UITableView section separator using Eureka

257 Views Asked by At

I'm using the Eureka framework for styling the grouped UITableView, and I want to hide the thin separator that appears between the Section header and the first cell of the section (but leave the separator in the first section). The code below hides separator correctly but only when the cell appears on the screen. When I open the controller and see the TableView, the separator is there and I need to scroll the cell off the screen and scroll it back to make it work. Is there any way to hide the separator? On the screenshot below the Height cell has hidden separator (what Im trying to achieve) and Current weight cell still presents the separator. Is there any way to hide the separator right away?

The Height cell has hidden separator and Current weight cell still presents the separator

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    
    if let divider = cell.subviews.first(where: { $0.frame.minY == 0 && $0 !== cell.contentView }) {
        divider.isHidden = indexPath.section != 0 && indexPath.row == 0 ? true : false
    }
    
    cell.setNeedsDisplay()
    
    return cell
}
1

There are 1 best solutions below

4
Maksim Chizhavko On

Try to reload your table view in viewDidLoad ow viewWillAppear