I have an UITableView
that has multiple rows. The user is only allowed to select 1 row. I want to show the grey selection effect only while touching the row, not after the row is selected.
I set the selection effect to Grey in interface builder. This allows me to see the selection effect while touching, but it also shows the grey selection color after I made my selection. To fix this I tried the following code from https://stackoverflow.com/a/10402278/6414904:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = self.tableView.cellForRow(at: indexPath) as! AnswerTableViewCell
tableView.deselectRow(at: indexPath, animated: true)
}
This works partly. When I select a cell it only shows the Grey selection effect while touching the cell but after selecting a cell the grey selection effect is gone. This is what I want but with this code added it also allows the user to select multiple rows which I do not want. With this approach I also can't use the didDeselectRowAt
method for other functionalities.
How do I create a selection effect which only shows during touch/hold but is removed after a selection while only allowing 1 row to be selected at all times?