From the examples I've seen unwind segue needs a view controller to unwind to. If i just want to go back one controller in my storyboard is there a simple command for this?
Asked
Active
Viewed 711 times
2
-
How did you go "forward" to that view controller? – jrturton Apr 08 '14 at 10:45
-
Possible duplicate: http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them – Michal Apr 08 '14 at 10:51
-
@michael - this example requires specific destination segues – Jeef Apr 08 '14 at 10:52
-
@jturnton I used preformseguewithidentifier to go forward or I just used a segue created in IB. I don't keep track of previous view controller however – Jeef Apr 08 '14 at 10:52
-
which type of segue are you using? push, custom or any other? – Atul Apr 08 '14 at 11:11
-
Maybe I'm looking at this wrong -> I just want to programmatically hit the back button basically. – Jeef Apr 08 '14 at 11:15
-
You're not looking at it wrong, you just didn't explain it very well :) Answered now. – jrturton Apr 08 '14 at 11:18
2 Answers
7
If you've pushed onto a navigation controller (push segues, with a visible back button) then you use this code to go back:
[self.navigationController popViewControllerAnimated:YES];
If you've used modal segues, use this:
[self dismissViewControllerAnimated:YES completion:nil];
In both cases self
is the currently visible view controller.

jrturton
- 118,105
- 32
- 252
- 268
-
1Just in case anyone needs it, `dismissViewControllerAnimated` doesn't (at least, for me) work for **custom segues**. Use `self.performSegueWithIdentifier("idCustomSegueUnwind", sender: self)`. Does anyone know how my custom segue will be performed when `dismissViewControllerAnimated` is called? – ton Nov 20 '15 at 03:40
0
In the newest version of swift it will work like this:
dismiss(animated: true, completion: nil)
Assuming you call this in the view controller script.

Rietveld
- 1
- 1