19

In iOS 9, storyboards can be connected by a 'storyboard reference' that links to a second storyboard by adding a storyboard reference and setting the 'referenced ID' to the name of another storyboard file.

Is it possible to set up an unwind segue in the second file that unwinds to a scene in the first file? If so, what steps are involved, either in Interface Builder or in code?

Iain Delaney
  • 562
  • 4
  • 17

3 Answers3

9

I didn't have to make a storyboard reference back from the 2nd storyboard to the first as Ryan laid out. For me, in my second storyboard I could Control-drag from a viewcontroller to its own exit, and the unwind segue that I had specified in a viewcontroller class consumed in the first storyboard appeared. So I just selected that to create a new exit segue with an identifier, and called performSegueWithIdentifier: on it in code. Worked fine.

xaphod
  • 6,392
  • 2
  • 37
  • 45
  • 1
    It didn't work for me. Nothing happens when I programmatically call the performSegueWithIdentifier. Do you know what might be happening? – K.K Jul 28 '17 at 05:09
  • Is it related to how we initiate the navigation to the first screen in the second storyboard? i.e.: Switch or Modal? – Mo Zaatar Sep 06 '17 at 23:53
  • Right click on from VC's own Exit, select the unwind method previously defined, drag to from VC. – Morten Holmgaard Aug 14 '19 at 11:30
8

Starting from your storyboard reference, create a new storyboard reference that will be a reference back to your "Main" storyboard. Make sure you set your Storyboard Identifier on your main as well.

You will now have a "Main Scene" reference with all you Exits now available. You can now create unwind segues as you normally would. Ctrl-drag from your controller to the Exit marker on the Main Scene and you will be able to select the desired exit.

enter image description here

Ryan Romanchuk
  • 10,819
  • 6
  • 37
  • 41
7

1) Add this method to your MainViewController

// NEEDED! Do not delete!
@IBAction func unwindToMasterViewController(_ segue : UIStoryboardSegue) {
  // Do nothing
}
2) In the Main storyboard, right-click on the Exit segue of the referenced storyboard and select unwindToMasterViewController

Interface Builder

3) Give the exit segue a name to reference it in code

Attributes Inspector

4) Call your exit segue from code

rjobidon
  • 3,055
  • 3
  • 30
  • 36