Search code examples
iosviewdeckiiviewdeckcontroller

ViewDeck removes navigation bar when setting center controller


I am currently using ViewDeck with Storyboards, and have the following setup in the application didFinishLaunchingWithOptions:

//View Deck Setup
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftSideMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;

self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self.viewDeckController;

However, when I am setting a new CenterController from my MenuViewController, the navigation bar is removed, even if loading the same center view controller as I was previously looking at.

- (IBAction)viewUsers:(UIButton *)sender
{
    UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
    UIViewController* viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"middleViewController"];

    [self.viewDeckController setCenterController:viewController];
    [self.viewDeckController closeLeftView];
}

What am I doing incorrectly?


Solution

  • The solution is remove any "deck constructor" class between AppDelegate and you TabBar. When you need to set or change Deck structure I create a several methods for each one structure. For example, if you want Deck has "leftView" view controller in left side, "rightView" in the right and "tabBarHome" in center, create a method like this in App Delegate:

    -(void) lanzarHome{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    IIViewDeckController* deckController =[[IIViewDeckController alloc] initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:@"tabBarHome"]
                                                                        leftViewController:[storyboard instantiateViewControllerWithIdentifier:@"leftView"]
                                                                        rightViewController:[storyboard instantiateViewControllerWithIdentifier:@"rightView"]];
    
    deckController.leftSize = 100;
    self.window.rootViewController = deckController;
    [self.window makeKeyAndVisible];
    

    }

    Now, you must call this method from your viewController with sentence like this:

    [((VKAppDelegate*) [[UIApplication sharedApplication] delegate]) lanzarHome];

    The most important think is that create the method that changes or inits Deck structure from AppDelegate and never you have another class or viewController between delegate and center TabBar.

    I hope this answer solve your issue. For me was a very hard work to find out this issue.