我需要我的应用程序记住上次UIViewController
打开的应用程序,因此当应用程序加载到内存不足时,我用保存的一个rootViewController
属性替换:AppDelegate
NSUserDefaults
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
frontViewController = [[SGLoginScreenViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
我想做的是在ViewDidLoad
each 的方法中放入一些代码ViewController
并记住它的名称NSUserDefaults
以便以后在 中使用它didFinishLaunchingWithOptions
,如下所示:
[[NSUserDefaults standardUserDefaults] setObject:self forKey:@"currentViewController"];
[[NSUserDefaults standardUserDefaults] synchronize];
然而,问题是 XCode 给了我这个警告:
*** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<SGMainScreenFirstTimeViewController: 0x8e1fea0>' of class 'SGMainScreenFirstTimeViewController'. Note that dictionaries and arrays in property lists must also contain only property values.
关于如何实施这整件事的任何想法?提前致谢