I have 3 views called A,B and C. The segue between them is "present modally". dismissViewControllerAnimated
can be used to jump back to parent view controller, but does it have a way to jump from C to A directly?

- 987
- 2
- 8
- 16
-
possible duplicate of http://stackoverflow.com/questions/30304026/how-to-pop-stack-in-ios/30304177 – Bhavin Bhadani May 19 '15 at 04:37
4 Answers
If you're using a storyboard, you can use an unwind segue to back up multiple steps in a view controller hierarchy.
- Define a method on view controller A of the form
- (IBAction)unwind:(UIStoryboardSegue *)segue
. It needs to take a segue as the argument, not just anyid
sender. - Hook up a segue action from view controller C to the exit proxy in the white bar above the controller's view. You should see a menu pop up with a list of unwind segue selectors; pick the one you defined earlier.
Unwind segues work by walking the parent and presenting view controller hierarchy until they find a controller that implements the chosen method. You don't have to put any code in this method; just to have it exist with an empty body is enough. Once the storyboard finds such a method, it will pop and dismiss view controllers until it reveals the one that implements that method.

- 59,527
- 19
- 156
- 165
if you want to directly jump to A and A is you rootViewcontroller then you can use this code in you C controller
self.navigationController?.popToRootViewControllerAnimated(true)
but if you want to pass a certain data from C controller to A controller then you have to use Segue these all are mentioned in navigationController class refer to : https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html

- 1,543
- 1
- 11
- 19
Use Navigation stack for Push and Pop ViewControllers, and if you need to present and dismiss viewController then , you can try with UIAnimation with Navigation Push and Pop stack,
And then you can easily navigate to Parent ViewController with below Code.
[self.navigationController popToViewController:self.navigationController.viewControllers[self.navigationController.viewControllers.count - 3] animated:YES];
Hope , this may help you. !!!!!

- 286
- 1
- 6
-
1I had used unwind segue but your answer demonstrates a really good way, thank you. – Don_Chen May 19 '15 at 07:02
Objective - C
UIViewController *prevVC = [self.navigationController.viewControllers objectAtIndex:IndexViewOfA];
//you get index of view (A,B,C) from array self.navigationController.viewControllers
[self.navigationController popToViewController:prevVC animated:YES];
This might helps you :)