How to go to particular viewcontroller from leftviewcontroller in IIViewDeck in storyboard?

261 Views Asked by At

I am having difficulty using IIViewDeck in my app. I am using storyboard. I have managed to bring leftviewcontroller which is a tableviewcontroller with cells that are supposed to segue to particular viewcontroller in the storyboard. How do I do this? I have put this in appdelegate.

 UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

UIViewController *menuController = [mainStoryboard    instantiateViewControllerWithIdentifier:@"mainSideNavMenu"];

UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self->viewDeckController =  [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self->viewDeckController;
2

There are 2 best solutions below

0
On

I know it's a bit late, but someone might find the answer useful at some point.

Max's answer is generally a good answer. However, the original poster's question is a bit vague. He/She didn't specify if the transition is required in the center view controller or the left one.

Assuming the transition is in the left view controller:

If you want push transition, you can use a code like:

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        UINavigationController * nc = (UINavigationController *)self.viewDeckController.leftController;
        UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourView"]; // use the name of the view (not the navigation view controller)
        [nc pushViewController:vc animated:YES];
    }
}

If you want Modal transition, just replace the code within the previous if statement clause with the following code:

UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"]; // don't use the name of a navigation controller
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nc animated:YES completion:nil];

The navigation controller in this code is used to get the navigation bar shown. If you don't need the navigation bar, just omit the navigation controller definition and pass the view controller as a parameter instead in the presentViewController: animated: completion: method.

Assuming the transition is in the center view controller:

You can use the code Max had provided. Keep in mind that the way he showed the new view controller is by replacing the existing center view controller. The new view controller is neither pushed nor modally showed. If you want to push new view controller to the existing center view controller, you should use the same way I introduced the transition in the previous two pieces of code above. So, it should look like this:

Push Transition: (the following code should replace the code within the if statement clause in the first piece of code)

[self.viewDeckController closeLeftView];
UINavigationController * nc = (UINavigationController *)self.viewDeckController.centerController;
[nc pushViewController:[[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"] parentViewController] animated:YES];

Modal Presentation: (the following code should replace the code within the if statement clause in the first piece of code)

[self.viewDeckController closeLeftView];
UINavigationController * center = (UINavigationController *)self.viewDeckController.centerController;
UIViewController * vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"yourViewName"];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
[center presentViewController:nc animated:YES completion:nil];
0
On

You can manage it with code, with the didSelectRowAtIndexPath method of your table view.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

if (indexPath.row == 0) {
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController1"];
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
        self.viewDeckController.centerController = newController;
    }];
}
if (indexPath.row == 1) {
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController2"];
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
        self.viewDeckController.centerController = newController;
    }];
}
else {
    MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:@"ViewController3"];
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
        self.viewDeckController.centerController = newController;
    }];
}

}

So you have to defined you row / viewController couple.