0

Have a lot of trouble trying to implement SWRevealViewController:

GitHub Link

I've followed a few different tutorials and still can't get it to work. After I've followed the directions:

  1. import SWRevealController Obj-C Files
  2. add bridging header and import SWRevealController
  3. add viewcontroller to storyboard and set class "SWRevealViewController"
  4. I have a login screen so I added a navigation controller before the login screen and hid the navigation bar on this view
  5. have the login screen segue to the revealViewController
  6. add tableViewController and create segue w/ identifier "sw_rear" class "none", I've tried this also having the class as "SWRevealViewControllerSegueSetController"
  7. add segue w/ identifer "sw_front" that connects to the navigation controller which is connected to my home screen and added the class "SWRevealViewSegueSetController"
  8. added the menu item
  9. made an outlet for the menu item
  10. added the following code in viewDidLoad

    if revealViewController() != nil {
        print("this is running")
        menuButton.target = revealViewController()
        menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }
    

When I load up the app there are no errors and when I click on the menuButton nothing happens.

Any advice would be great, I've been trying to figure this out for two days.

**Edit - Just noticed that the pan gesture recognizer seems to bring me back to my login page **Edit - Also wanted to note that menu item I added is a button, not an image....

ryanbilak
  • 383
  • 1
  • 2
  • 13

1 Answers1

0

Since your menu button is a button, instead of the 2 lines to set target and action, use the following to add the target/action:

menuButton.addTarget(revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:)), forControlEvents: .TouchUpInside)

The other thing to check is if revealViewController() is actually pointing to your SWRevealViewController or not. It may be nil in some cases! Check out the following discussion on how to ensure that your view controller (where you are setting the menu button) actually has a working pointer to your SWRevealViewController: finding SWRevealViewController

auspicious99
  • 3,902
  • 1
  • 44
  • 58