8

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!

Tom Holder
  • 311
  • 4
  • 5

4 Answers4

12

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)
    
webjunkie
  • 1,184
  • 9
  • 19
  • This one is working for me but before make sure the story board connection is disconnected. – vijay Sep 23 '16 at 07:09
  • This works but how do I make it reflect in the rearview which option was selected? Ex. it was the third option in the menu list? – Famic Tech Jul 30 '18 at 15:35
5

I've kind of made some progress. I can load in a new view controller, but it doesn't animate in anyway. The code to do this, on a button click is:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("TARGET_VIEW_CONTROLLER") as! UIViewController
var rvc:SWRevealViewController = self.revealViewController() as SWRevealViewController
rvc.pushFrontViewController(vc, animated: true)
Tom Holder
  • 311
  • 4
  • 5
0
  1. Download SWRevealViewController project's zip form Github.
  2. Drag SWRevealViewController.m and SWRevealViewController.h files from zip (SWRevealViewController folder) to your project, and Click “Yes” to the prompted message "Would you like to configure an Objective-C bridging header?"
  3. Take a look at storyboard in RevealControllerStoryboardExample2 project. Design your storyboard with this example.
Vlad
  • 7,199
  • 2
  • 25
  • 32
  • Thanks, but I was specifically asking about swift. I can see that code here https://github.com/John-Lluch/SWRevealViewController/blob/master/RevealControllerExample2/RevealControllerProject2/RearViewController.m might do it, but I can't translate this to swift. – Tom Holder Apr 22 '15 at 10:44
  • Storyboards do not depend on Swift or Obj-C. My answer is specified for Swift, take a look on second step. – Vlad Apr 22 '15 at 10:50
  • And your link is wrong, this file will be useful for you https://github.com/John-Lluch/SWRevealViewController/blob/master/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/en.lproj/MainStoryboard.storyboard Download all project and take a look. – Vlad Apr 22 '15 at 10:58
  • 1
    Sorry, perhaps I didn't make myself clear. I have the project working in a swift project absolutely fine. Steps 1 and 2 have been done and are working. What I can't find is a swift code example to manually perform a segue. I have it working with static table cell content without any issue. – Tom Holder Apr 22 '15 at 11:06
  • Sorry, I misunderstood your question. I thought you want to configure your SWRevealViewController with segues and storyboard. – Vlad Apr 22 '15 at 11:17
  • No, thanks, but that's all working well and was pretty easy. It's just how to do a programatic segue in swift. One of those links has helped a bit though, I might be able to translate in to swift, but my objective c is weak. – Tom Holder Apr 22 '15 at 11:37
  • I can help if you specify what exactly you want to do. SWRevealViewController has no `showViewController` method. I configure it programmatically with `SWRevealViewController(rearViewController: frontViewController:)`. You can push another front controller with `pushFrontViewController:animated:`. – Vlad Apr 22 '15 at 12:03
  • Thanks, I'll have a play around with that. – Tom Holder Apr 22 '15 at 12:07
0

This is not how it should be done, but at least i found a way to do it.

In the TableViewController where u have the slideOut menu do something like:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if(indexPath.row == <some position> ){
            let vc: AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("YOUR_DESTINATION_IDENTIFIER")
            self.showViewController(vc as! SWRevealViewController, sender: vc)
        }

The one that satisfy the condition will segue with default animation, not like the slide out menu normally does.

After, in storyboard, do a normal Reveal View Controller Push controller, and as long as it doesn't satisfy the condition it will exit the slide out menu normally

Cano
  • 13
  • 5