我需要我的应用程序记住这是最后UIViewController
打开,这样,当应用程序被加载了的记忆,我代替在AppDelegate
一个rootViewController
财产与一个保存在NSUserDefaults
:开放应用程序打开的UIViewController
- (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;
}
我想要做的就是把一些代码在每个ViewController
的ViewDidLoad
方法和记住它的名字在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.
就如何落实这件事正确的任何想法?在此先感谢
编译器如何知道什么是“classStringSavedInUserDefaults”? –
编辑我的回答,现在应该更清楚:) – Vlad
那帮了!非常感谢! –