Michael Reiland
Michael Reiland

Reputation: 849

Bypass UIView without showing

I am using Storyboards for an iOS 7 App. The root controller is a menu. For almost every view, I have a Menu button which brings the App back to that menu using [self.navigationController popToRootController:TRUE]. However, there are two UIView elements where I would like to clear the Navigation Controller view list (as happens when you pop back to the root controller), but then immediately go to another UIView without having the user see the root controller's view. Once at this new view, if the user presses the back button, I want them to go to the menu view.

I've tried to put a performSegue in the viewWillAppear, but it really messes up the Navigation Controller and views. I've tried putting a performSegue in the viewDidAppear, but the user sees first the Menu view flash in, then out on it's way to the correct view.

I hope I've explained this well enough. I hope this can be done.

Thanks.

Upvotes: 0

Views: 41

Answers (1)

Andrew Monshizadeh
Andrew Monshizadeh

Reputation: 1784

Your best bet is to build the navigation controller stack yourself, and then use - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated: to replace the current stack.

So you could do something like

...
UIViewController *vcToPush = ...;
NSArray *newVCStack = @[[self.navigationController.viewControllers firstObject], vcToPush];
[self.navigationController setViewControllers:newVCStack animated:YES];

This will add your new controller to the stack using the standard push animation (or not if you so choose), and after the animation is complete, set the view stack to that of the array.

Upvotes: 1

Related Questions