Question

I have made on application using Xcode 4.5. and also use UIStoryboard in this application.

In this app, I push from one ViewController to second ViewController and then push from second ViewController to third ViewController.

Now, How I can Pop (back) directly from third ViewController to first ViewController.

Is it possible or not ? If possible, then How?

Was it helpful?

Solution

This is possible , Just use this..

  [self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex:0] animated:YES];

You can change value of objectAtIndex with any controller's value you want to pop

OTHER TIPS

use this methode

popToRootViewControllerAnimated:

apple doc

Pops all the view controllers on the stack except the root view controller and updates the display.

  • (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

Parameters animated : Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.

Return Value : An array of view controllers that are popped from the stack.

Example of use

 [self.navigationController popToRootViewControllerAnimated:YES];

You can use popToViewController and check if the view controller is in the stack by using the below code.

for (UIViewController *aViewController in self.navigationController viewControllers)
{
    if ([aViewController isKindOfClass:[firstViewController class]])
                        {
                            firstViewController *FVC = (firstViewController*)aViewController;
                          [self.navigationController popToViewController:FVC animated:YES];
                        }
                    }

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top