Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable selected table cell highlight after returning from Detail View (Back Segue)

I am having problem with my table view cell. I can't disable the highlight of table cell selection after returning from detail view to main table view using segue with embedded navigation controller. The table cell is still selected. I don't want the table cell selection to be disable when I click one of them to show the detail. I only want to disable them after I returning back from detail view.

like image 977
Thiha Aung Avatar asked Feb 19 '15 08:02

Thiha Aung


2 Answers

I got it now. I solved like this. It's simple theory.

We just deselect it when we select the row

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
}
like image 187
Thiha Aung Avatar answered Nov 07 '22 05:11

Thiha Aung


The way I like to do it, if you have single selection enabled is to use the viewDidAppear Method. That way the user can see the deselection animation when he returns to the tableView.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(true)
    if let selectedRow = tableView.indexPathForSelectedRow {
        tableView.deselectRow(at: selectedRow, animated: true)
    }
}
like image 27
André Kuhlmann Avatar answered Nov 07 '22 06:11

André Kuhlmann