Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing multiple UIViewControllers in NavigationController

I have 6 subclassed UIViewControllers connected with push segues with identifiers.

They go A>B>C>D>E>F. I am unable to find a way how to implement button in the controller A which would automatically stack all controllers up to controller F and display F controller. Stacking should be done in UINavigationController instance, not through(void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated, because if I use setViewControllers method, then I lose segue identifiers. Ty!

like image 948
Snsa Kscc Avatar asked Feb 12 '23 11:02

Snsa Kscc


1 Answers

You should be able to do it with pushViewController:animated:, like this:

// This method belongs to view controller A class
-(void)pushToF {
    // I am assuming that A is already in the navigation controller
    UINavigationController *nav = self.navigationController;
    UIViewController *b =[self.storyboard instantiateViewControllerWithIdentifier:@"B"];
    [nav pushViewController:b animated:NO];
    UIViewController *c =[self.storyboard instantiateViewControllerWithIdentifier:@"C"];
    [nav pushViewController:c animated:NO];
    ... // And so on, until F
    UIViewController *f =[self.storyboard instantiateViewControllerWithIdentifier:@"F"];
    // You can push the last one with animation, so that end users would see it
    [nav pushViewController:f animated:YES];
}
like image 124
Sergey Kalinichenko Avatar answered Feb 16 '23 02:02

Sergey Kalinichenko