2

enter image description here

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?

Don_Chen
  • 987
  • 2
  • 8
  • 16

4 Answers4

1

If you're using a storyboard, you can use an unwind segue to back up multiple steps in a view controller hierarchy.

  1. 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 any id sender.
  2. 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.

Tim
  • 59,527
  • 19
  • 156
  • 165
1

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

Fatti Khan
  • 1,543
  • 1
  • 11
  • 19
1

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. !!!!!

VD Patel
  • 286
  • 1
  • 6
0

UINavigationController_Class

popToViewController:animated:

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];

popTOViewController

This might helps you :)

Community
  • 1
  • 1
Yuyutsu
  • 2,509
  • 22
  • 38