Ios6 在iOS 6上保存和恢复应用程序状态而不使用故事板
我已经做了以下的测试应用程序 我试着不使用故事板就做同样的事情,但这是行不通的。我已在AppDelegate中启用状态保存和恢复。我已将restorationIdentifier分配给所有控制器及其视图。我想我必须在AppDelegate中实现一些额外的代码来恢复rootviewcontroller,但我找不到正确的方法来实现这一点Ios6 在iOS 6上保存和恢复应用程序状态而不使用故事板,ios6,storyboard,xib,state-saving,Ios6,Storyboard,Xib,State Saving,我已经做了以下的测试应用程序 我试着不使用故事板就做同样的事情,但这是行不通的。我已在AppDelegate中启用状态保存和恢复。我已将restorationIdentifier分配给所有控制器及其视图。我想我必须在AppDelegate中实现一些额外的代码来恢复rootviewcontroller,但我找不到正确的方法来实现这一点 -(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSC
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[StateTestFirstViewController alloc] initWithNibName:@"StateTestFirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[StateTestSecondViewController alloc] initWithNibName:@"StateTestSecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.restorationIdentifier = @"TabBarController";
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我在尝试实现这一点时也遇到了不少问题 首先,您是否成功地利用故事板完成了这项工作? 您的代码看起来不错,不需要其他任何东西,因为只有两个要求:
- 点击模拟器主页按钮
- 使用Xcode停止应用程序
- 使用Xcode播放应用程序
希望有帮助;) 实际上,视图控制器是在
应用程序:willFinishLaunchingWithOptions:
和应用程序:didFinishLaunchingWithOptions:
之间恢复的,因此如果您将代码更改为:
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[StateTestFirstViewController alloc] initWithNibName:@"StateTestFirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[StateTestSecondViewController alloc] initWithNibName:@"StateTestSecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.restorationIdentifier = @"TabBarController";
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
return YES;
}
这对我有用。我还建议你看电视