分享

iphone

 quasiceo 2015-03-28

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 on it nor work out how it can be used.

Anyone know anything about it, how it works, what its for?

asked Sep 13 '12 at 23:06
Josh Kahane
4,4501269151
1  
On a similar question I posted this answer: /questions/12569316/… It helps explain how to use the exit (unwind) feature –  Eric Nov 18 '12 at 3:03

4 Answers

up vote 67 down vote accepted

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.

answered Sep 17 '12 at 14:37
Alladinian
18.6k24252
1  
OK, so how do you use it? Tried control-clicking from the exit object at the bottom of a viewcontroller, but it wouldn't link to anything. –  shim Oct 22 '12 at 3:59
3  
You basically have to define a method for your unwind segue and then connect from an element to the exit button selecting the method you wish to call. You can find an example here (I have updated my answer as well to include the example) –  Alladinian Oct 22 '12 at 8:18
    
-1: Lots of words, little useful information. After reading up on this and utilizing it in my own app, I wrote up this answer which is hopefully more useful: /a/25829835/901641 –  ArtOfWarfare Sep 14 '14 at 3:38
    
This is why I love Apple non-existent documentations. Man, someone should be fired there. –  SpaceDog Sep 23 '14 at 22:44

See also Cannot Connect Storyboard Unwind Segue which clarifies the requirements to bring the Exit icon to life. You must have, higher up in the view controller hierarchy, a method that is:

  1. Marked as IBAction

  2. Takes one parameter that is a UIStoryboardSegue*

If both those conditions are met, the Exit icon will see it and will permit you connect through to it by control-dragging from a button in the same view controller.

I have also now posted the world's simplest example here:

https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch19p638presentedViewControllerStoryboard (fixed 12 July 2013)

This shows how trivially easy it now is to segue to and back from a presented view controller, as opposed to all the work you had to do previously in order to hand info back and forth (the stuff in the template with a delegate and a protocol, all of which can now be deleted).

answered Oct 26 '12 at 17:52
matt
91.4k20135234

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:

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.
}

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./fmslabs_blog/2012/9/24/advanced-storyboard-techniques.html

answered Sep 14 '14 at 3:37
ArtOfWarfare
3,93333258

Just adding a slight subtlety to the requirements definition that might help. This is based on experimenting in Xcode 4.6. I found that it is specifically and only the declaring(!) of the method that enables the desired control-drag response from Xcode. Here's what I found to be the full requirements:

  • Marked as IBAction
  • Takes one parameter that is a UIStoryboardSegue*
  • You must have an action declared (but not necessarily implemented [meaning a method in the .M implementation section]).
  • It can be in any class's interface declaration, even the interface section of a .M, except the appdelegate class. (I did not see any dependency on its position in the controller hierarchy. You can add any old file and the system seems to aggregate all the methods that have the UIStoryboardSegue parameter and display them on the Exit icon's menu.) Note that the control-drag menu will even show you your method if the method is in the class of the scene you are manipulating in the storyboard editor, but it will appear without a colon and does not seem to trigger any action at runtime.

Example: -(IBAction)anymethodname:(UIStoryboardSegue *)myvariable;

answered Mar 18 '13 at 0:41

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多