Clicking multiple UIViewControllers in a NavigationController

I have 6 subclasses of UIViewControllers associated with push segues with identifiers.

They go A> B> C> D> E> F. I can’t find a way to implement the button in controller A, which would automatically fold all the controllers to controller F and display controller F. Stacking should be done in the UINavigationControllerinstance, and not through (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated, because what if I use the method setViewControllers, I lose the segue identifiers. Ty!

+4
source share
1 answer

pushViewController:animated:, :

// 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];
}
+7

All Articles