アプリが最後に開いたものを覚えておく必要がある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、それぞれのメソッドにいくつかのコードを入れ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.
この全体を正しく実装する方法についてのアイデアはありますか? 前もって感謝します