2

I am working on a UITableView with customized cells from a .xib. I have added a blue border to the top and bottom of the .xib to give a customized spacing between the cells. I don't want a separator between the cells so I set the Separator to None in the storyboard. This is the look that it gives me.

enter image description here

This works great until I select a cell, at which point I am seeing this (notice the white separators above and below the selected cell):

enter image description here

I am using this code in the cellForRowAt function to set the color of the selected cell to white, but this also seems to force the separator to be white:

let selectedView = UIView()
selectedView.backgroundColor = .white
cell.selectedBackgroundView = selectedView

I am trying to figure out how to remove the separator lines when the cell is selected. I have tried several things on the storyboard and in code, but haven't found anything that works.For example:

  • I can't use cell.selectionStyle = .none because I want the cell background to turn white when selected.
  • This doesn't change anything when called from viewDidAppear: tableView.separatorColor = UIColor.clear
  • I tried the answer here Hide separator line on one UITableViewCell by Avinash but it didn't do anything.

Any ideas?

Ryan Tensmeyer
  • 865
  • 10
  • 26

2 Answers2

1

I found that this solution worked for me.

I changed my code in the cellForRowAt function to the clear color:

let selectedView = UIView()
selectedView.backgroundColor = .clear
cell.selectedBackgroundView = selectedView
Ryan Tensmeyer
  • 865
  • 10
  • 26
0

try change the tableView.separatorColor = tableView.backgroundColor and set you table style to grouped

  • Thanks for the suggestion. Unfortunately this didn't change anything. The style is set to grouped. I have tried setting tableView.separatorColor to several different values and none of them make a difference. – Ryan Tensmeyer Nov 30 '18 at 18:01