Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 685
hanumanDev Avatar asked Feb 19 '13 11:02

hanumanDev


Video Answer


1 Answers

If you using UITableViewController subclass then just set property

self.clearsSelectionOnViewWillAppear = YES; 

else in viewWillAppear just call

NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow; if (indexPath) {     [self.tableView deselectRowAtIndexPath:indexPath animated:animated]; }  // MARK: - Swift 3 if let indexPath = tableView.indexPathForSelectedRow {     tableView.deselectRow(at: indexPath, animated: true) } 
like image 94
iiFreeman Avatar answered Oct 09 '22 02:10

iiFreeman