1

I want to return to previous view controllers from current one. the situation is like this: A,B,C,D are view controllers. A presents B, B presents C, C presents D. i know use delegate can from D to C, C to B, B to A. Now i want to return to A from D directly. How to do this? Any suggestions are appreciated.

chancyWu
  • 14,073
  • 11
  • 62
  • 81
  • I do believe this is a duplicate question: http://stackoverflow.com/questions/10003562/ios-how-to-segue-back-to-a-uiviewcontroller-thats-already-loaded – chimgrrl Nov 19 '12 at 04:01
  • i didn't use uinavigationcontroller. its just normal view controllers. – chancyWu Nov 19 '12 at 04:07
  • You might want to use `UINavigationController` and push/pop rather than modal transitions and present/dismiss. – Rob Nov 19 '12 at 04:08
  • I see UINavigationController is a better solution. I wonder if normal view controller, can we still do the same ? – chancyWu Nov 19 '12 at 04:10
  • 1
    If I understand your question, once you have your navigation controller, the view controllers that you navigate within there are just plain old controllers, nothing fancy. You just need to replace your `[self presentViewController ...]` references with `[self.navigationController pushViewController ...]`. And replace `[self dismissViewControllerAnimated ...]` with `[self.navigationController popViewControllerAnimated ...]`. (Or if using segues, replace modal segues with push segues.) – Rob Nov 19 '12 at 04:13
  • This way, you can use all of the tools that chimgrrl and Woodenlabs suggested. Much easier way to jump "back" multiple controllers (from D to A, for example). – Rob Nov 19 '12 at 04:14
  • 1
    @Rob thanks, maybe i need to read UINavigationController guide. – chancyWu Nov 19 '12 at 04:17

1 Answers1

8

Use below statement:

[self.navigationController popToRootViewControllerAnimated:TRUE];

or

for (UIViewController *vc in [self.navigationController viewControllers]) {

    if([vc isKindOfClass:[A class]])
    {
        [self.navigationController popToViewController:vc animated:TRUE];
    }
}

thanks

Rob
  • 415,655
  • 72
  • 787
  • 1,044
Hindu
  • 2,894
  • 23
  • 41