PDA

View Full Version : restoring state to a navigation controller with table views




North Bronson
Aug 8, 2009, 02:21 PM
Here's something I've been wondering for a while:

Take a look at one of Apple's apps (like Mail) that restores state across a Navigation Controller. If you start your app on a leaf controller and you pop back to a table view, the "selected" table cell de-selects, as if it was selected to push you to the leaf in the first place.

I can't figure out the best way to do this. Right now, I have a working app that saves state.

I thought about, while restoring the state, actually calling the appropriate tableView:didSelectRowAtIndexPath: method, but this would then load the appropriate table view, which seems like a waste if I'm just skipping over that view in the first place. This is why my current code to restore does a programmatic push without touching the table view. This doesn't give me the highlighted cell when I pop back, though.

Any ideas?



PhoneyDeveloper
Aug 8, 2009, 04:04 PM
selectRowAtIndexPath:animated:scrollPosition:

would seem to be what you're looking for.

North Bronson
Aug 9, 2009, 03:14 PM
selectRowAtIndexPath:animated:scrollPosition:

would seem to be what you're looking for.

I thought about this, but then I'm back at my original problem.

If my hierarchy has three levels with a leaf controller at the end, restoring to the leaf controller pushes through two table view controllers. Using the selectRowAtIndexPath:animated:scrollPosition: method would load two separate table views "on the way", but the programatic push I'm using now bypasses loading the table views.

I guess I could try something in the viewWillAppear:animated: for each table view controller that would check to see if the table view should "de-select" a cell. There might be a cleaner way, though

rick.andrews
Sep 20, 2009, 02:40 AM
This is a little late, but if you're still looking: search the ADC iPhone Reference Library for "DrillDownSave" -- it sounds exactly what you were looking for.