Alexander Deplov – Senior Product Designer Blog

How to Deselect Selected UITableView Cell

· Alexander Deplov

You have UITableView with customized cells style, selection color, etc. When you tap on the cell, slide to another VC and came back, your cell still selected. Really annoing. Here is how to fix that.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if let selectedIndexPath = tableView.indexPathForSelectedRow {
        tableView.deselectRow(at: selectedIndexPath, animated: true)
    }
}

Let's connect on LinkedIn!