开发者

Remember Apps last screen in iPhone app

I want to remem开发者_运维百科ber the last screen of my app, means if I reopen my app, app should navigate me to the last screen where I were just before exiting app.

Thanks Saurabh


Take a look at the NSUserDefaults API.

You could save an object for the current screen in the NSUserDefaults then check for that object on launch.

Create a NSMutableDictionary object when a view loads, and change it's value each time, and store it in the user defaults.

NSMutableDictionary *currentScreen = [[NSMutableDictionary alloc] init];
[currentScreen setObject:@"AboutPage" forKey:@"screen"];

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:currentScreen forKey:@"lastScreen"];

Then when the app loads, check the user defaults "lastScreen" key and load the appropriate view.

Hope this helps.


in iOS4 it's done automatically, because when you quit your application it's actually enters the background mode and doesn't quit. So when you "launch" it again, it opens at the same place the user left.

Previous versions of iOS don't have this feature and you should take care of it by yourself.


Depending on your application, you may want to think about using the Three20 library. This library has the sort of persistence you are looking for built in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜