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.
Asked
Active
Viewed 6,590 times
1
-
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
-
1If 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 Answers
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
-
If I don't use navigation controller, just normal view controller, this still can work? – chancyWu Nov 19 '12 at 04:08
-
How did you push from one view controller to another view controller? Can you post your moving code here? – Hindu Nov 19 '12 at 04:18
-
-
maybe i need to change to UiNavigationController, thanks for your anser. – chancyWu Nov 19 '12 at 04:24