views:

302

answers:

2

Hi,

I am having trouble finding some information on persistence in iPhone apps. I am creating a tab based - navigation based app and want the application to save the current location when the app quits. For example if the user is in tab 1, several tiers into the navigation controller and the app quits, I would like the app to load up in the same place the next time it loads.

If anyone can point me in the direction of a good book/tutorial that would be great.

Cheers


Just to make it clear, I know that I would need to save the data somewhere and that NSUserDefaults seems to be the best way to do this. What is confusing me is what to actually save when the app is closed and then how to load it so that the correct view is loaded.

+3  A: 

NSUserDefaults

http://icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/

zinc
Thanks for the quick reply, what I was more interested in was what to actually save. I have some NSUserDefaults already being saved, but I don't know what to save so that when the user restarts the app it knows what to load.
Jack
Oh sorry - as Ed mentions below "NSIndexPath of the items the user clicked on to get to his current position." then save it using NSUserDefaults
zinc
+2  A: 

Obviously, you'll need to save the tab you're displaying, and whatever sort of data storage you want to use to manually determine where the user is. If you're using a drill-down sort of system where your data is in arrays that the user opens, then I would suggest saving an NSIndexPath of the items the user clicked on to get to his current position.

Then, on app startup, first switch to the correct tab, then load the index path and create the necessary views and set the navigation controller's stack using [navigationController setViewControllers:animated:]

Ed Marty
Spot on. That's the method I was looking for. So basically I should save the indices of the data that is navigated through then use that method.
Jack