2

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?

UPDATE: Ok, it seems like pushing from UIViewController to UIViewController works. But pushing from UIViewController to UITableViewController and vice versa, don't work. The app crashes if the tableview implements the UIViewControllerRestoration protocol. If I don't implement the protocol, UIViewControllers pushed from the tableView is not preserved.

How should one treat UITableViewControllers to preserve them without a crash?

UPDATE: No crashing no more.. It was due to a memory bug specific for my app. But the tableView is still not preserved, neither the pushed viewController.

UPDATE: The reason my tableview did not restore properly was because I deleted my datasource in the background.. But I still have a problem with modal viewController not showing up when I try to push it on another navigationController than self.navigationController. I set the restoration identifier to this modal navigationController, but the view does not show up.

user2908112
  • 457
  • 6
  • 18
  • have you given a restorationIdentifier to navigation controller, check this following [stare-restoration-without-storyboard](http://petr-pavlik.squarespace.com/blog/2013/6/16/stare-restoration-without-storyboard), [UINavigationController State Restoration (without Storyboards)](http://stackoverflow.com/questions/14376786/uinavigationcontroller-state-restoration-without-storyboards/17363529#17363529) – Pawan Rai Aug 20 '14 at 10:29
  • Yes, I have. I tried the navigationController from storyboard but no luck. Only tableviewControllers implementation of UIViewControllerRestoration that is somehow wrong.. – user2908112 Aug 20 '14 at 14:23

1 Answers1

1

The modal transition needs to be backed by a UINavigationController which has a restorationIdentifier and either a restoration class or a corresponding implementation in the app delegates method viewControllerWithRestorationIdentifierPath. That solved the last piece of the problem.

user2908112
  • 457
  • 6
  • 18