Swift tableViewCell stays selected

31 views Asked by At

When I go selected a cell in my VC and go to another VC, and then back again to the first VC, the cell is still selected. I found some answers here and on the Medium but they didn't work.

I tried this in didSelectRowAt but it makes no sense because I will never be able to select a row if I put this at the beginning of the method:

tableView.deselectRow(at: indexPath, animated: false)

I also found this solution but it didn't work, too:

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

        let selectedRow: IndexPath? = tableView.indexPathForSelectedRow
        if let selectedRow = selectedRow {
            tableView.deselectRow(at: selectedRow, animated: true)
        }
        else {
            print("no selected rows found")
        }
    }

The method above always prints no selected rows found

0

There are 0 answers