我一直在尝试实施状态恢复和保存,但没有任何运气。
我没有使用故事板。我一定是做错了什么。
我为每个 Nib 文件设置了恢复标识符。
我知道状态正在被存储,但从未正确恢复。最后一个状态显示半秒钟,然后返回主视图。我尝试了很多没有运气的事情。请帮忙!
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"will finish");
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
navigator = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigator;
[self.window makeKeyAndVisible];
[navigator release];
NSLog(@"did finish");
return YES;
}
// As you can see, I started the process of saving and restoring application state.
// Also, I added the restoration identifier for every class that should be restored.
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
NSLog(@"restoring");
return YES;
}
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
-(void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"restored");
//navigator = [[UINavigationController alloc] initWithRootViewController:];
isRestored = YES;
}