Search code examples
swiftuisplitviewcontroller

segue from UITableViewController to UISplitViewController Swift - Iphone App


I have implemented a SWRevealViewController menu having as a rear view a UITableViewController with few labels on it. What I want to do is to segue from these label to a UISplitViewController. When I ctrl click and drag from a label to UISplitViewController, no segue option shows. Here is a screenshot of Main.storyboard

enter image description here

Also there is no way I can embed the UISplitViewController in a UINavigationController, when I go to Editor/Embed in, all options are greyed.


Solution

  • You can in fact do this with a UINavigation controller in combination with a container view and a second view controller.

    1. Add a UINavigationController to your storyboard and ensure it's set as the initial view controller:

    2. Delete the unnecessary table view controller that Xcode automatically added
    3. Add a UIViewController to your storyboard (let's rename it VC1)
    4. From the storyboard navigation tree, ctrl+drag from the navigation controller to VC1 and select root view controller under Relationship Segue from the popup:
    5. Add a UIButton to VC1:

    6. Add a second view controller to the scene (let's rename it VC2)

    7. Add a Container View to VC2, replacing the initial view (drag it over top of the view so it highlights gray):

      If you did it right, it should look like this:

    8. Delete the unnecessary View Controller that Xcode automatically added to the scene and embedded in the container view, then add a Split View Controller to the scene in its place

    9. ctrl+drag from VC2's container view to the Split View Controller and select Embed:
    10. Last but not least, add a show (prev. push) segue from the button in VC1 to VC2 -- ctrl+drag from the button in VC1 to the VC2 controller and select Show: