Best way to load an application like it was in its previous state when it was terminated

I would like to learn the best practices in reloading the application state, such that when my app is started, it should automatically load the "correct" view/subview when it is opened again.

In my particular case, my app has a bunch of view controllers, each taking care of a UITableView. I would like for my app to "jump" to the correct node within my table view hierarchy when it is opened again.


Building on what Marc said, assuming you've got a base view controller, and then one or more levels of 'drill-down', load all your view controllers up to the 'current' one using [navigationController pushViewController: viewController animated: NO]. Then, when the user hits the Back button, they'll be presented with the pre-loaded previous view controller. A good example of this is the "Contacts" app, which preloads the Groups view controller, then pushes a view controller for the current group (usually "All Contacts") on top of that.

Check Apple's DrillDownSave sample app:

"Demonstrates how to restore the user's current location in a drill-down list style user interface and restore that location when the app is relaunched."

You'll need to associate an identifier with each view controller, and save that value to the user defaults when the current view changes. The next time you launch, read that value and you'll know which view controller you need to load initially.

I've published a little library to help doing these kinds of things. I'm already using it in an app I've published on the App Store and it's a lot smoother than implementing NSCoder for every view manually :P

Need Your Help

How can I get the ViewController instance starting from subView

ios objective-c uiviewcontroller uiimageview

I've an object of UIImageCustom that extend UIImageView, and in a method this class I want to get instance the ViewController, where my object UICustom is added.

WCF: WTF! Does WCF raise the bar or just the complexity level?

wcf web-services

I understand the value of the three-part service/host/client model offered by WCF. But is it just me or does it seem like WCF took something pretty direct and straightforward (the ASMX model) and m...