5

I have looked for this problem everywhere. I know how the unwind scene works. I have implemented the following code in the A VC

-(IBAction)returned:(UIStoryboardSegue *)segue {
try.text = @"Returned from Scene 1";
}

But when I go to my B VC(Which is the VC I want to go back to A VC from) and ctrl drag a button onto the exit at the bottom it will not allow me to. And no function pops up in the exits option. Anyone else had this issue or can help?

Sfocker
  • 101
  • 2
  • 8
  • Did you add the public declaration to A's .h? Also what's the type of segue from A to B? – Rob Mar 19 '13 at 21:59
  • B is a subclass of A? Should that do it? – Sfocker Mar 19 '13 at 22:00
  • 1
    No. You should have two scenes on your storyboard, one whose custom class is A, the other's whose is B. You should then have push or modal segue from A to B. And if A's unwind action us defined in A's .h, When you drag from a control on B to B's exit outlet, you should see your unwind segue listed there. – Rob Mar 19 '13 at 22:09
  • This is what I have defined in A's .h `- (IBAction)returned:(id)sender;` – Sfocker Mar 19 '13 at 22:11
  • 1
    It should match the method: `-(IBAction)returned:(UIStoryboardSegue *)segue;` (personally, I'm not crazy about that name ... I'd call it `unwindToA` or something like that; You want something that is descriptive when using IB (imagine that you had a whole series of scenes that preceded B ... you'd like it to be obvious that you're going to A); I also like to follow the `verbNoun` format when it works.) – Rob Mar 19 '13 at 22:18
  • That did the trick Rob. Thanks very much. Sorry if the question was very basic – Sfocker Mar 19 '13 at 22:27
  • You actually don't need to declare that method in the .h file at all, but I think having it there with the wrong signature was your problem. – rdelmar Mar 19 '13 at 23:03

4 Answers4

18

To set up an unwind segue, you should

  1. Set up your two scenes with the standard modal or push segue between them:

    enter image description here

  2. Define the custom classes for those two scenes to be your respective view controllers.

  3. Implement the action in the .m for view controller A:

    - (IBAction)unwindToA:(UIStoryboardSegue *)segue
    {
        //returning to A
    }
    
  4. Then you can create a segue in B by control-dragging (or right-click-dragging) from some control down to the exit outlet in the bar below scene B:

    enter image description here

  5. And if everything above is configured correctly, you will now see your unwind segue listed in a popover:

    enter image description here

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • 1
    You don't actually need the declaration in the .h, Xcode still finds it as long as you implement a method with the correct signature. – rdelmar Mar 19 '13 at 23:16
  • @rdelmar Thanks. Removed unnecessary .h declaration from my answer. – Rob Mar 19 '13 at 23:19
4

To make Exit outlet active, add this code to viewController. Now you should be able to ctrl-drag to exit outlet. It is actually quite odd, that there should be empty method to make it work.

swift
@IBAction func unwindSegue(unwindSegue:UIStoryboardSegue) 

objC
- (IBAction)unwindSegue:(UIStoryboardSegue *)sender;
  • 1
    I find that for beginners, they tend to forget the `@IBAction` keyword for the Interface Builder to discover the unwind function. – jackxujh Aug 04 '18 at 22:31
1

I also had a problem with this even though everything was set up correctly. Eventually I tried closing the project and reopening it and that did the trick. Must have been some bug in Xcode.

This doesn't seem to have been the cause of your problem but I thought I'd add the answer in case someone else has the same problem.

LoPoBo
  • 1,767
  • 1
  • 15
  • 26
  • Hey the same is happening to me! Just randomly now I have no more "Exit" popups. But I closed and reopened Xcode and it still doesn't work! Arghhh – Van Du Tran Feb 21 '14 at 16:08
  • Fixed it by removed the Derived data and restarting Xcode. – Van Du Tran Feb 24 '14 at 15:07
  • Facing the same issue, there are no "Exit" popups even restarting does not seems to work for me. Is there any other way to fix this? – hozefam Apr 17 '14 at 08:04
  • Does your method in the destination view controller conform to the format `- (IBAction)unwindMethodName:(UIStoryboardSegue *)segue`? – LoPoBo Apr 22 '14 at 08:19
0

@LoPoBo, @hozefam, & @Van Du Tran

If closing down isn't working, perhaps you were dragging in the wrong manner. Instead of clicking on the Bar Button Item and dragging from Action Segue to the exit try just right click -> hold & drag to exit segue. This was messing with me for a good 20min before I figured it out. Hope this helps someone else too. Using xcode 6.1