Why do my UITableViewCells turn grey when I tap on them?
Swift 3
Option 1: (Which I always use)
To give it fade out animation after selected with gray you can do this:
func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
Option 2:
To remove the highlight effect completely you can add this line to your cellForRowAt
:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = .....
cell.selectionStyle = .none
return cell
}
This is the default behaviour of UITableView.
You must call deselectRowAtIndexPath
inside of didSelectRowAtIndexPath
inside your UITableViewController class.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
Check out the iOS Documentation for more information.
UITableView
UITableViewDelegate