Reputation: 479
I have six viewControllers
. On viewController1
I have a button
which takes me to the viewController6
.
Now from viewController6
I want to pop back to viewController5
, viewController4
, viewController3
, viewController2
and viewController1
respectively.
How can I do this?
Upvotes: 2
Views: 1920
Reputation: 14834
Use [self.navigationController pushViewController:] in this order: from ViewController1, 6, 5, 4, 3, 2.
And use [self.navigationController popToRootViewControllerAnimated:] to go from ViewController2 to 1.
Upvotes: 0
Reputation: 4164
Use either
popToViewController:animatedor
setViewControllers:animated
Upvotes: 0
Reputation: 3905
Try this,
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
Insert your required view controllers in order using
[allViewControllers insertObject:viewControllerX atIndex:requiredIndex];
If you want to replace only previous viewController use,
[allViewControllers replaceObjectAtIndex:indexRequired withObject:viewControlerX];
Then set back the navigation stack,
self.navigationController.viewControllers = allViewControllers;
Then you can use following to pop back to any viewController :
[self.navigationController popViewControllerAnimated:YES];
Upvotes: 3
Reputation: 3192
Yes this is Possible .
if you want to pop 1 ViewController
from controller stack
[self.navigationController popViewControllerAnimated:YES];
go back to the fist ViewController
.
[self.navigationController popToRootViewControllerAnimated:YES];
For More Information use this Link
Upvotes: 0
Reputation: 7343
You can use [self.navigationController popViewControllerAnimated:YES];
if you want to pop just 1 ViewController
, or use [self.navigationController popToRootViewControllerAnimated:YES];
to go back to the fist ViewController
Upvotes: 0