hanumanDev hanumanDev - 1 year ago 69
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

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download