Reputation: 65476
Is there any in-built technique for moving straight to the last UIViewController shown before quiting your app?
I'm trying to figure out if there are any inbuilt ways of doing this with the UIKit framework /Cocoa Touch. If not I realise it will be fairly trivial to implement, but I don't want to do this if something already exists.
For example:
You then restart the app and want to be back on that last view you were at step 3 - viewing your fifth item.
Upvotes: 1
Views: 356
Reputation: 119214
NSUserDefaults will be the tool for this job. You could simply save a key to indicate your position in the app, and then read this key again when the app launches to decide where to go:
// whenever you move to a new screen or item:
[[NSUserDefaults standardUserDefaults] setObject:viewIdentifierString
forKey:@"last_view"];
// when your application opens:
NSString * viewIdentifierString = [[NSUserDefaults standardUserDefaults]
stringForKey:@"last_view"];
if (viewIdentifierString == nil)
{
// show default view
}
else
{
// use viewIdentifierString to determine which view to load
}
Upvotes: 3
Reputation: 25254
you can store your last viewed viewcontroller to a NSUserDefaults
for example.
then in your app delegate read out this value and load the appointed view controller.
overwrite your NSUserDefaults value on every init of your viewcontrollers or when your app gets terminated.
Upvotes: 1