Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manual segue with SWRevealViewController in Swift

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!

like image 396
Tom Holder Avatar asked Apr 22 '15 08:04

Tom Holder


People also ask

How do I segue to navigation controller in Swift?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

What is Swrevealviewcontroller in iOS?

A UIViewController subclass for revealing a rear (left and/or right) view controller behind a front controller, inspired by the Facebook app, done right!


1 Answers

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)
    
like image 68
webjunkie Avatar answered Nov 16 '22 00:11

webjunkie