Can't Unwind Between Storyboards

I have a two storyboards.

StoryboardA has a storyboard reference to StoryboardB. I present a viewcontroller from StoryboardB using a button action (user taps a button and it shows the viewcontroller in storyboardB).

storyboardB has a Cancel button. This button is linked to an IBAction within the view controller which then calls performSegueWithIdentifier. In StoryboardB I have ctrl dragged from the storyboard scene to the exit to create an unwind segue. I've assigned "cancelSegue" as the identifier of this unwind and use it in the performSegueWithIdentifier call.

However when I then call the performSegueWithIdentifier, nothing happens. I have log output on the destination unwind IBAction and have put breakpoints. No log output happens and no breakpoints are hit. No error or anything. The fact that when I ctrl dragged to the exit to create the unwind segue tells me that StoryboardB can see the segues from StoryboardA.

I've tried things such as in this StackOverflow post from a number of years ago but none of it worked. https://stackoverflow.com/questions/33369171/can-an-unwind-segue-work-between-two-storyboards-connected-by-a-storyboard-ref

I'm deploying to iOS15 and am on xCode 14.0.1.

What else do I need to do to get this unwind to work?

If I understand your set up.

You only have to:

  • create IBAction in the return class (which is displayed in storyboard A)
  • this IBAction has no code and the circle on its left will remain empty
    @IBAction func unwindToControllerA(_ sender: UIStoryboardSegue) {
    }
  • connect the cancelButton in storyboardB to the exit icon of its VC
  • select unwindToControllerA in the popup that appears

Is it what you did ?

Nothing more, no need for performSegue.

If you look at the VC in storyboardB in Interface Builder, you will see the segue in the list of objects. You can give it an identifier.

Claude31 thanks for the reply. You are correct. This is what I did. However I have some logic in the button's IBAction which then requires me to use performSegueWithIdentifier. This code snippet may clarify why...

- (IBAction)cancelButtonPressed:(id)sender
{
	if (self.objectId != nil)
	{
		[self performSegueWithIdentifier:@"cancelSaveExisting" sender:nil];
	}
	else
	{
		[self performSegueWithIdentifier:@"cancelCreate" sender:nil];
	}
}

I use the same viewcontroller for creating an object based on user input as well as when they want to edit that data.

Either than that, everything you mentioned is the same.

Problem is that you have both code in the button and segue.

Or you should create the unwindSegue from the VC, by control-drag from the VC button to the exit button, not from the cancelButton.

Turns out I had the unwind segue in the wrong class. My bad. I just needed to step away for awhile and come at it with fresh eyes.

Can't Unwind Between Storyboards
 
 
Q