Reputation:
I am not using storyboards. And currently in ViewController1. Here on a button click event I call this code.
InnerViewController *innerVc = [[InnerViewController alloc] initWithNibName:@"InnerViewController" bundle:nil titleText:@"vaibhav"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:innerVc];
nav.restorationIdentifier = @"innerNavSR";
[self.navigationController presentViewController:nav animated:YES completion:nil];
And in InnerViewController restorationIdentifier
and restorationClass
is given. I have proper methods written for restoration.like
viewControllerWithRestorationIdentifierPath
encode and decode restoration.
If I change my
[self.navigationController presentViewController:nav animated:YES completion:nil];
to
[self.navigationController pushViewController:innerVc animated:YES];
It works fine. What am I missing or doing wrong with present. For a try I have even tried this :
[self presentViewController:nav animated:YES completion:nil];
But no use. Doesn't work.
Result when presenting is -
viewControllerWithRestorationIdentifierPath
and decodeRestorableStateWithCoder
are getting called. call is also coming in viewdidload
but not in viewwillappear
. and I am visually seeing Viewcontroller1
. However it is all fine with push
Is something special required with present ??
Upvotes: 4
Views: 724
Reputation: 41
I have had a very similar issue and struggled for half a day. The problem was I was assigning a restoration identifier when regularly creating the view controller, but was NOT assigning it, when creating the restored instance.
In your particular scenario, make sure, that when restoring the inner NC, it is also assigned @"innerNavSR" identifier before it is returned to the OS.
Hope that helps.
Upvotes: 4