このようにAppDelegate.mに追加uinavigationcontroller
しました
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController];
nav.restorationIdentifier = @"nav1";
self.window.rootViewController = nav;
私のViewController.mは次のようになります
- (void)viewDidLoad
{
[super viewDidLoad];
self.restorationIdentifier = @"secondViewController";
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction)click:(id)sender {
secondViewController *svc = [[secondViewController alloc]initWithNibName:@"secondViewController" bundle:nil];
svc.restorationIdentifier = @"secondViewController";
svc.restorationClass = [self class];
[self.navigationController pushViewController:svc animated:YES];
}
私のsecondViewController.mのような
+(UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
NSLog(@"viewControllerWithRestorationIdentifierPath");
UIViewController * myViewController =
[[secondViewController alloc]
initWithNibName:@"secondViewController"
bundle:nil];
return myViewController;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
label.text = @"sdfkheiowodhnskjfdgewluri3y2oejdscndjshfiledhdsfhewilufhyeows";
// Do any additional setup after loading the view from its nib.
}
-(void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"encodeRestorableStateWithCoder");
[coder encodeObject:label.text forKey:@"UnsavedText"];
[super encodeRestorableStateWithCoder:coder];
}
-(void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
NSLog(@"decodeRestorableStateWithCoder");
[super decodeRestorableStateWithCoder:coder];
label.text = [coder decodeObjectForKey:@"UnsavedText"];
}
出力中
encodeRestorableStateWithCoder を取得しますが、この後、ホーム ボタンを押してアプリケーションを再度実行すると、アプリケーションの状態が secondViewController に表示されず、decodeRestorableStateWithCoder が呼び出されません。
どこが間違っているのかわかりませんか?