Why does UITableViewCell remain highlighted?

前端 未结 18 1278
余生分开走
余生分开走 2020-12-12 12:45

What would cause a table view cell to remain highlighted after being touched? I click the cell and can see it stays highlighted as a detail view is pushed. Once the detail

18条回答
  •  再見小時候
    2020-12-12 12:55

    If none of these work for you, consider this work-around:

    Use an unwind segue to call:

    @IBAction func unwind_ToTableVC (segue: UIStoryboardSegue) {
        if let index = tableView.indexPathForSelectedRow {
            tableView.deselectRowAtIndexPath(index, animated: true)
        }
    }
    

    Why do this? Primarily if you're having trouble getting the deselect code to run at the right time. I had trouble with it not working on the viewWillAppear so the unwind worked a lot better.

    Steps:

    1. Write the unwind segue (or paste from above) into your 1st VC (the one with the table)

    2. Go to the 2nd VC. Control-drag from the Cancel/Done/Etc button you're using to dismiss that VC and drag to the Exit Icon at the top.

    3. Select the unwind segue you created in step 1

      Good luck.

提交回复
热议问题