Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I maintain the UITableView selected row when returning from a UINavigationController child screen?

I have a UITableView of customers where a row/customer is selected. The user can then push another view on the UINavigationController stack to add a new customer. When I pop the child screen and return to the UITableView the previously selected row is no longer selected.

I can re-select the row in viewDidAppear() but it looks bad as you can see the deselect and the select. Is there a way to maintain the selected row when returning from the child screen?

like image 416
ChrisP Avatar asked Jul 22 '11 19:07

ChrisP


1 Answers

I assume you are using a table view controller, as otherwise it is your responsibility to write this behaviour anyway. In a table view controller, though, it's easy. Just add in viewDidLoad:

self.clearsSelectionOnViewWillAppear = NO;

That will keep the row selected, unless you manually deselect the row or the user selects another row on the table.

like image 81
Benjamin Mayo Avatar answered Oct 19 '22 07:10

Benjamin Mayo