3
以下是我在做什麼:如何在iPhone中使用NSUserDefaults保存應用程序狀態?
- (void) applicationWillTerminate: (UIApplication*) application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:navigationController.viewControllers
forKey:@"diabetesstate"];
}
- (void) applicationDidFinishLaunching: (UIApplication*) application {
NSMutableArray *state = [[NSUserDefaults standardUserDefaults]
objectForKey:@"diabetesstate"];
if (state == nil) {
//Will initialize a new controller and put it as root view controller
}
else {
[navigationController setViewControllers:state animated:NO];
}
}
它工作嗎?如果不是,爲什麼?你期望代碼做什麼,它究竟做了什麼? – zoul 2010-06-08 06:21:30