Do note that every answer which mentions "selectionStyle" is completely wrong.
selectionStyle
determines whether or not you can click on the cell.
It has nothing to do with whether the cell is turned "gray" when you click on it.
The only way to turn off the "gray effect" (when you click on it) is like this:
class YourCell: UITableViewCell {
override func didMoveToSuperview() {
selectedBackgroundView?.isHidden = true
}
...
}
Note that selectedBackgroundView
is indeed available on the storyboard.
I wouldn't fool with it because the lifecycle is so strange, but note that these days, indeed you can get at selectedBackgroundView
on the storyboard. It's possible you could handle it in there.
The answer by @fingia, see below.
Regarding the question on this page, how to "remove the cell highlight color", notice that the @fingiua answer correctly states that you adjust selectedBackgroundView
. However, it states that what you do is change the background color.
This used to work in the past to some extent and is still possible in certain situations but it's a hell of a task figuring out when in the lifecycle you have to set the color - because, UIKit itself is constantly setting the color! (For example, if you do it in the obvious didMoveToSuperview or prepareForReuse ... it simply doesn't work.)
This is a great example of how, on the internet, for obscure yet critical issues, there is often a lot of VERY OLD example code on the internet, which gets copied endlessly, which is either just wrong or "half wrong", but still gets copied endlessly.
There's no reason at all you'd fool with the color, because what you want to do is simply ... hide it. So just hide it. This (of course) works reliably (indeed, you can do so anywhere at all in the view cycle, once it's hidden that's the end of it).