1

I want cell separators in every single one of my sections other than section 0.

enter image description here

Between "New Game", "Friends", "Random", "Judge", and "Challenges" I don't want any separators. The cell type in section "0" or "New Game" is different than the other sections' cell types so I tried this: iOS swift remove UITableView Cell separator space but it didn't work.

Another issue I'm facing is how to erase the space left when a header is gone because it has no rows in it.

Here is a picture:

enter image description here

As you can see, "Waiting For Opponent" has disappeared because there are no rows in the section.

So to be extremely clear:

  1. How do I conditionally hide the separators in section 0 without hiding the entire tableView's separators?
  2. How do I hide the space that is created when I hide a section header?
Community
  • 1
  • 1
Wesley Cho
  • 495
  • 8
  • 23

1 Answers1

0
  1. I can think of two options:
    • Hide the separators entirely and implement your own separator by adding a UIView with 1-2pt height placed at the bottom of the cell which can then be hidden/unhidden based on your requirements in cellForRowAtIndexPath.

      OR

    • In cellForRowAtIndexPath, change the insets of the separator for that cell so that the separator goes out of the view. Eg: cell.separatorInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, cell.bounds.size.width-cell.layoutMargins.left)

  1. Have you tried returning zero in tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat ??
Santhosh R
  • 1,518
  • 2
  • 10
  • 14