我一直在努力实施国家恢复和保护。
我没有使用故事板。我必须做错事。
我为每个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;
}
答案 0 :(得分:0)
您应该在application:willFinishLaunchingWithOptions:
中进行控制器初始化,因为在调用application:didFinishLaunchingWithOptions:
之前已完成恢复。
检查this answer。
此外,您应该以编程方式将restorationIdentifier分配给所有控制器。