Cannot Connect Storyboard Unwind Segue
Asked Answered
D

4

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?

Dispassion answered 9/10, 2012 at 3:50 Comment(1)
On a similar question I posted this answer: #12569816Oaks
E
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://mcmap.net/q/102538/-cannot-connect-storyboard-unwind-segue

Explorer answered 9/10, 2012 at 4:16 Comment(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.Dispassion
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.Explorer
In case anyone else misses it, you can add this to ANY view controller and it will show up in the EXIT iconKamal
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.Accentor
@SteveMoser you don't have to put it in the .hStillage
B
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.)

Bubb answered 11/10, 2012 at 16:14 Comment(2)
Correct. It's all a little confusing at first IMO but seems to work out well.Dispassion
Fantastically useful answer; I added some more info which may help folksFanelli
K
1

Upvote for Jon Hess! This is the swift 3 equivalent

@IBAction func unwindToViewController(segue: UIStoryboardSegue) {

    //code

}
Kosse answered 13/9, 2017 at 13:38 Comment(0)
P
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.

Probable answered 31/7, 2014 at 8:19 Comment(2)
Nah, this was years ago. The method signature was causing the problem.Dispassion
Ohhh sorry didn't saw that it was years ago. Anyway glad the the problem got solvedProbable

© 2022 - 2024 — McMap. All rights reserved.