Search code examples
iosswiftuisplitviewcontroller

Segueing to new Master and Detail controllers simultaneously in Swift


I am creating a Split View application in Xcode. When an initial Master table view cell is selected I need to segue to a new detail and also replace the master with a new controller.

I almost achieved this by triggering the master segue from within prepareForSegue, this way it loaded both segues at the same time. This worked fine until in compact width where you see the app load one segue after the other. In compact size class I wouldn't need to load the detail.

How can this be achieved, is there a best practice?


Solution

  • In your prepareForSegue (in the place where you "load both segues at the same time"), you can check the state of your SplitViewController's collapsed property.

    If it's not collapsed, you should perform the second segue, else you don't.