24

I am attempting to create an unwind segue but nothing will connect to it when ctrl+dragging. Also when I right click on the Exit icon there are no options available.

enter image description here

Any ideas?

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
  • 1
    On a similar question I posted this answer: http://stackoverflow.com/questions/12569316/does-anyone-know-what-the-new-exit-icon-is-used-for-when-editing-storyboards-usi/13437054#13437054 – Eric Nov 18 '12 at 03:02

4 Answers4

67

You need to have an IBAction defined on a view controller that takes an argument of type "UIStoryboardSegue *".

Something like this:

@interface MyViewController
...
- (IBAction)unwindFromConfirmationForm:(UIStoryboardSegue *)segue {
}
...
@end

Swift 3 Version

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {

    //code

}

Provided by DoruChidean in https://stackoverflow.com/a/46199117/250190

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
Jon Hess
  • 14,237
  • 1
  • 47
  • 51
  • Ahh yes! Thank you, works perfect. It's just a matter of defining the UIStoryboardSegue argument. I had it setup as `done:(id)sender`. – Chris Wagner Oct 09 '12 at 04:33
  • I'm glad I could help. The extra strictness is there so that every action in your project doesn't come up as a choice. – Jon Hess Oct 09 '12 at 04:35
  • 5
    In case anyone else misses it, you can add this to ANY view controller and it will show up in the EXIT icon – Undeadlegion Mar 07 '13 at 23:46
  • 1
    Another issue I had was that I didn't put my unwind segue method signature in my .h file or class extension. After I added it the unwind segue showed up in the popup. – Steve Moser Sep 06 '13 at 15:05
  • 1
    @SteveMoser you don't have to put it in the .h – Van Du Tran Jan 08 '15 at 15:43
19

Just to clarify, to link this up in storyboard, after adding the above method to the "view controller you want to unwind to" you need to drag a segue from a button or whatever in your "view controller you want to unwind from" down to it's own little green "EXIT" icon in the bottom bar.

There should be a popup to link to "- unwindFromConfirmationForm".

Once that's done, the unwind segue should work.


Just adding to Travis excellent point: to be utterly clear:

Say you've just started experimenting with storyboards so you (a) made a new iOS7 Xcode project and (b) made a story board with one navigation controller, and then (c) you've made five or six view controllers. You aim to be able to go-and-fore between the half-dozen view controllers using unwinds. {It is trivial to go "forward" by control-dragging from a button in one, to, the next one.}

Now, at this moment: all six of the view controllers, will indeed be the "default" class "ViewController". Note that Xcode (somewhat pointlessly) gives you a ViewController.h and ViewController.m file.

Again, all six of your "simple example" views are indeed just using that file ViewController.m, at this moment. So, very simply, if you add this:

-(IBAction)unwindUnused:(UIStoryboardSegue *)segue
    {
    NSLog(@"I did an unwind segway! Holy crap!");
    }

To that one "stub" file ViewController.m - in fact, every one of your six views will now "work", you'll be able to drag to the infamous small green "Exit" button. It's that easy.

Now just TBC normally in a real project, you'd never use the default "ViewController.m" file. So, go here:

https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html

and find down to precisely "Create Custom View Controllers", and it of course explains that process in excellent detail if you're new.

But again, if you're just fooling around and want to make the green button work for unwinds, simply put the code fragment in the "ViewController.m" stub file, and you're away. (Remembering that in "real life" you'd put a custom such call in each of your custom screens - likely dealing with data, etc etc.) Hope it helps!!

Bonus factoid: Note that a "Back" button will, anyway, automatically appear on the navbar when you're just testing like this! (i.e., even if you don't add the unwind stub method.)

Fattie
  • 27,874
  • 70
  • 431
  • 719
Travis M.
  • 10,930
  • 1
  • 56
  • 72
1

Upvote for Jon Hess! This is the swift 3 equivalent

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {

    //code

}
DoruChidean
  • 7,941
  • 1
  • 29
  • 33
0

Are your working with xcode6-beta version? in beta 1-3 is a bug which prevents interface builder from detecting unwind segues. in xcode6-beta4 this bug has been fixed.

Fred
  • 421
  • 2
  • 6