Restore and preserve UIViewController pushed from UINavigationController, no storyboard
Posted
by
user2908112
on Stack Overflow
See other posts from Stack Overflow
or by user2908112
Published on 2014-08-20T10:02:10Z
Indexed on
2014/08/20
10:20 UTC
Read the original article
Hit count: 208
I try to restore a simple UIViewController that I pushed from my initial view controller. The first one is preserved, but the second one just disappear when relaunched. I don't use storyboard. I implement the protocol in every view controller and add the restorationIdentifier and restorationClass to each one of them.
The second viewController inherit from a third viewController and is initialized from a xib file. I'm not sure if I need to implement the UIViewControllerRestoration to this third since I don't use it directly.
My code looks like typically like this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.restorationIdentifier = @"EditNotificationViewController";
self.restorationClass = [self class];
}
return self;
}
-(void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
}
-(void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
}
+(UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
EditNotificationViewController* envc = [[EditNotificationViewController alloc] initWithNibName:@"SearchFormViewController" bundle:nil];
return envc;
}
Should perhaps the navigationController be subclassed so it too can inherit from UIViewControllerRestoration?
© Stack Overflow or respective owner