hanumanDev hanumanDev - 13 days ago 5
iOS Question

How to unselect a uitableview cell when the user returns to the view controller

I have a uitableview cell highlighted when a user selects it and then is pushed to a detail view. I would like the cell to be unhighlighted when they return to the table view view controller.

how would I go about accomplishing this?

I'm guessing

[cell.textLabel setHighlighted:NO];
in viewWillAppear, but cell is undeclared if I put it there.

thanks for any help


If you using UITableViewController subclass then just set property

self.clearsSelectionOnViewWillAppear = YES;

else on viewDidAppear just call

NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
if (indexPath) {
    [self.tableView deselectRowAtIndexPath:indexPath animated:animated];