State saving, navigation controller stack saving and gesture recognizer on the navigation bar

453 views Asked by At

I'm loading my view controllers like this:

NSArray *viewControllerNames = [NSArray arrayWithContentsOfFile:path];
    for (NSString *viewControllerClass in viewControllerNames) {

        NSString *filePath = [self filePathForClass:NSClassFromString(viewControllerClass)];
        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
            id viewController = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:filePath]];

            [self pushViewController:viewController animated:NO];
        }
    }

On my stack's root view controller I am adding a gesture recognizer in the navbar.

However if I pushed some view controller on top it won't load this gesture, because the root view controller's viewDidLoad doesn't get called, and if I access the viewControllers property of UINavigationController it returns nil.

Any ideas how to proceed with this gesture? Thanks!

1

There are 1 answers

2
barley On BEST ANSWER

How about using setViewControllers:animated: instead of pushing single view controller one by one?

NSMutableArray * viewControllers = [[NSMutableArray alloc] init];
for(...) { // the same for loop you have 
    ...
    [viewControllers addObject:viewController];
}
[self setViewControllers:viewControllers animated:YES];