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?

1

4 Answers 4

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

5
  • Ahh yes! Thank you, works perfect. It's just a matter of defining the UIStoryboardSegue argument. I had it setup as done:(id)sender. Oct 9, 2012 at 4: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 9, 2012 at 4: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 Mar 7, 2013 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. Sep 6, 2013 at 15:05
  • 1
    @SteveMoser you don't have to put it in the .h Jan 8, 2015 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.)

2
  • 1
    Correct. It's all a little confusing at first IMO but seems to work out well. Oct 11, 2012 at 17:11
  • Fantastically useful answer; I added some more info which may help folks
    – Fattie
    Mar 29, 2014 at 19:45
1

Upvote for Jon Hess! This is the swift 3 equivalent

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {

    //code

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

2
  • Nah, this was years ago. The method signature was causing the problem. Jul 31, 2014 at 17:03
  • Ohhh sorry didn't saw that it was years ago. Anyway glad the the problem got solved
    – Fred
    Aug 2, 2014 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.