Brosef Brosef - 5 months ago 9
iOS Question

UITableViewController cell remains highlighted when segueing back

I have a

UITableViewController
and when a cell is selected, my app segues to a new view controller. When I press the back button in my navigation controller to go back to the previous tableview controller, the cell that I had selected remains highlighted. I checked
clearsSelectionOnViewWillAppear
in
viewWillAppeaer
and it is true. Any idea why this is happening?

Answer

Are you calling the segue from didSelectRowAtIndexPath if so try something like this

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("Your Segue", sender: indexPath)
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

You could also place tableView.deselectRowAtIndexPath the in the prepareForSegue method which is what I tend to do