-2

In a table view I'm hiding separator for empty cells only by following code which does hide separator for empty cells but it also doesn't show separator at all. I can't figure out why, any clue?

Alternatively is there any other way to hide separator for empty cells?

There is nothing wrong with the following code, it does work as intended on other VCs but on this particular VC it doesn't work as intended. I've checked storyboard and compared working and non working VCs. Both have exactly same attributes for the tableview.

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView()
}
Raymond
  • 1,108
  • 13
  • 32
  • This might help: https://stackoverflow.com/q/8561774/14351818 – aheze Feb 07 '21 at 19:26
  • I'm aware of that trick to set separator to none and then add a view inside cell to act as separator. It's overkill as the same can be achieved by above code which works for me on many VCs but on one VC it doesn't work and I can't figure out why. – Raymond Feb 08 '21 at 15:50

2 Answers2

1

You can do like this:

tableView.separatorStyle = UITableViewCell.SeparatorStyle.none

or :

tableView.separatorColor = .clear
zeytin
  • 5,545
  • 4
  • 14
  • 38
1

You can use this method:

tableView?.tableFooterView = UIView(frame: .zero)

It will still render separator but with empty frame, so it will not be visible for empty cells only, while original style will remain for filled one's.

Pedja
  • 66
  • 3
  • Unfortunately this also has same effect as the code in my question. There is nothing wrong with my code, there seems to be something else which is causing the issue as reported in the question. – Raymond Feb 08 '21 at 15:52
  • @Raymond Please share ViewController with the issue, so we can solve it together – Pedja Feb 09 '21 at 11:11