Is there a method to go back one view in the stack on a UINavigationController
? Or to a view with a specific title?
3 Answers
I don't mean to be rude, but this is really well documented. A google search or even an Apple documentation search on UINavigationController will turn up exactly what you need. To programmatically pop the current view controller you use:
[[self navigationController] popViewControllerAnimated:YES];
To pop to a specific view controller, you use:
[[self navigationController] popToViewController:controller animated:YES];
You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

- 24,438
- 4
- 73
- 99
-
3LOL, you're right - that was pretty silly. I even looked at that method a couple of times. In my defense I am really new to this and still grasping concepts - although popViewController is pretty much self explanatory when you new things don't alway click right away. – Slee Jul 20 '10 at 19:05
-
Hi... when i am using this [[self navigationController] popToViewController:controller animated:YES]; app is crashing... Can you please tell me why? – Steve Gear Oct 11 '12 at 11:12
-
@SteveGear There could be many reasons that it's crashing. Does the crash happen immediately, or is there a delay. Do you see the animation at all (assuming you've passed YES to the popViewControllerAnimated: call). Often when you get crashes during a view controller pop, there is some delegate you've set in the view controller that is still being accessed. This often happens when you've set your view controller as the delegate for a map view, for example. I can' be sure what the issue is without seeing some code and context for your issue. – Matt Long Oct 11 '12 at 16:59
Take a look at popViewControllerAnimated:
.
From the documentation: This method removes the top view controller from the stack and makes the new top of the stack the active view controller.
Usage is something like:
[aViewController popViewControllerAnimated:YES];

- 10,041
- 6
- 47
- 63
Swift 3 version
navigationController?.popViewController(animated: true)
To pop to a specific view controller, you use:
navigationController?.popToViewController(controller, animated: true)
You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

- 3,401
- 35
- 39