【发布时间】:2013-01-09 05:27:43
【问题描述】:
我需要我的应用记住上次打开的 UIViewController 是哪个,所以当应用加载到内存不足时,我将 AppDelegate 中的 rootViewController 属性替换为 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;
}
我想做的是在每个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.
关于如何实施这整个事情的任何想法对吗?提前致谢
【问题讨论】:
标签: iphone ios objective-c cocoa-touch uiviewcontroller