Go to the next controller using UINavigationController on iPhone

The program has a navigation bar and usually when you click a button in viewController1, it goes to viewController2. when a button is clicked in viewController2, it goes to viewController3. and the user can go back from viewController3 to viewController2, and then to viewController1, using the back button in the navigation bar.

I want to make a button that programmatically takes the user directly viewController3 from viewController1. then the user can switch from viewController3 to viewController2 to viewController1.

Is there a way to move two views to the navigation controller? or is this another way to achieve the desired behavior? How can I do it?

+7
objective-c iphone uinavigationcontroller
source share
3 answers

Sorry for misunderstanding your question. Because you want to press 2 view controllers and then go back to 1 to 1. I think the solution is now simple.

You just need to click the view controller 2 times, 1 without animation and 1 with animation:

[viewController1.navigationController pushViewController:viewController2 animated:NO]; [viewController2.navigationController pushViewController:viewController3 animated:YES]; 

So, for the user, this happens as if you only press 1, but behind the scenes you actually press 2 view controllers. Then, when you want to return, you just need to pop 1 on 1.

+9
source share

You can directly configure the navigation stack on the UINavigationController using. setViewControllers: animated:.

For example, if this code is somewhere in viewController1, as a button handler, click on it:

 NSMutableArray* viewControllers = [self.navigationController.viewControllers mutableCopy]; UIViewController* controller = [[MyViewController2 alloc] init]; [viewControllers addObject:controller]; [controller release]; controller = [[MyViewController3 alloc] init]; [viewControllers addObject:controller]; [controller release]; [self.navigationController setViewControllers:viewControllers animated:YES]; 

The business of creating upstairs with a mutableCopy call is that you save everything that is already in the navigation stack.

+4
source share

You can click 2 view controllers at the same time, but as soon as you click the first, the navigationController property on the current ViewController will become zero, since it is no longer on top of the stack, so you will need to make a link to it, I never tried to click 2 at a time with animation I'm not sure how it will look.

0
source share

All Articles