I have just installed Xcode 4.5 for iOS6 support, and I have seen a new icon called 'Exit' in my Storyboard, listed under my view controllers along with 'First Responder' etc. A little green icon labeled 'Exit'.
I can find anything about it, nor work out how it can be used. How does it work?
This is called an "Unwind Segue". Unfortunately there's no documentation for this so far except a brief mention on XCode 4.5 new features list that states:
Unwind segues can allow transitioning to existing instances of scenes in a storyboard
The good news is that there is a session from WWDC 2012 explaining those creatures (among other things).
You can just login to Apple's iOS Dev Center with your developer account details and then go to the WWDC 2012 videos page and watch "Adopting Storyboard in your App" (it's fifth from the top) The discussion of unwind segues starts at time 37:20.
Update: Here is some more info on the subject from Apple's documentation
A placeholder object named Exit for unwinding seques. By default, when a user dismisses a child scene, the view controller for that scene unwinds (or returns) to the parent scene—that is the scene that originally transitioned to the child scene. However, the Exit object enables a view controller to unwind to an arbitrary scene.
(From iOS6 docset > General > Getting Started)
And here is a nice example of how you can implement one
Another Update:
Here is a technical note from Apple regarding this topic.
Imagine you have a sequence of views in your storyboard:
A -> ... -> Z
You want to have a button on view Z
which allows the user to go all the way back to A
.
So what you need to do is give the view that you want to back all the way out to, in this case, A
, an instance method which is marked as a IBAction
and takes in a single parameter of type UIStoryboardSegue *
. The name of the method and variable don't matter. What you do within the implementation doesn't matter, either. Here's an example:
Obj-C:
In A
's Interface (not Z
's):
- (IBAction)cancelSignup:(UIStoryboardSegue *)unwindSegue;
In A
's Implementation (not Z
's):
- (IBAction)cancelSignup:(UIStoryboardSegue *)unwindSegue { // Only "implemented" to satisfy a respondsToSelector: search. // You can actually implement more stuff here, if you want, IE, if // you need to reach out to a server to mention that this screen was // returned to from a later screen. }
Swift:
In A
's source (not Z
's):
@IBAction func cancelSignup(unwindSegue: UIStoryboardSegue) { // Only "implemented" to satisfy a respondsToSelector: search. // You can actually implement more stuff here, if you want, IE, if // you need to reach out to a server to mention that this screen was // returned to from a later screen. }
Now, within your storyboard, control drag from an element on Z
(IE, a cancel button) to Z
's Exit
. It'll scan through all of the views higher up in the view hierarchy which have an IBAction
that accepts only a single UIStoryboardSegue *
as an action and list them for you to pick from.
Hopefully this was more straight forward and helpful than the existing answers. I found that this link was particularly useful, so if there's a detail you're still fuzzy on after reading my answer, maybe this can help you (I tried to just condense all the useful info from this long article into a short answer): http://www.freelancemadscience.com/fmslabs_blog/2012/9/24/advanced-storyboard-techniques.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With