Manual segue with SWRevealViewController in Swift

Tom Holder picture Tom Holder · Apr 22, 2015 · Viewed 9.4k times · Source

There is a great blog post over at http://www.appcoda.com/tag/swrevealviewcontroller/ that goes in to setting up SWRevealViewController which is a great component for slide out side menus (https://github.com/John-Lluch/SWRevealViewController)

Unfortunately, there are no swift examples of how to perform a manual segue.

Took a cleaner approach to storyboard support. SWRevealViewControllerSegue is now deprecated and you should use SWRevealViewControllerSegueSetController and SWRevealViewControllerSeguePushController instead.

I've tried something along the lines of:

let navigationController = self.window?.rootViewController as! SWRevealViewController;

let viewController = navigationController.storyboard?.instantiateViewControllerWithIdentifier("ImportFileSelect") as! ImportFileSelect

navigationController.showViewController(viewController, sender: self)

This doesn't work though. Any ideas? I've trawled the web for swift examples, my next step is to learn objective c!

Answer

webjunkie picture webjunkie · Aug 31, 2016

In order to work you'll need to following steps:

  • You need to instantiate the SWRevealViewController and then attach it to the root controller.
  • Then instantiate the destination controller.
  • Then create a navigation controller and set the destination controller as the rootViewController
  • Finally push the navigation controller with SWReveal

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    
    let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController
    
    self.view.window?.rootViewController = sw
    
    let destinationController = self.storyboard?.instantiateViewControllerWithIdentifier("StoryboardID") as! NameOfViewController
    
    
    let navigationController = UINavigationController(rootViewController: destinationController)
    
    
    
    sw.pushFrontViewController(navigationController, animated: true)