Zy Mazza Zy Mazza - 15 days ago 7
Swift Question

SWRevealViewController Swipe/Tap gesture not working properly

I've implemented

SWRevealViewController
according to the tutorials I've seen for a hamburger slide menu. Things are working great, except if I use the slide menu on a later page in the app, and then collapse it, and then go to an earlier page and try to use it, it will open, but no gestures will collapse it unless I navigate back to the page that last opened the menu. Then I can close it from there.

The code I'm using in the
viewDidLoad
of each
ViewController
is

let menuButton = self.navigationItem.rightBarButtonItem
if self.revealViewController() != nil {
menuButton?.target = self.revealViewController()
menuButton?.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())

}


Any ideas what's causing this/how to fix it?

Answer

Remove the code from ViewDidLoad and use it in ViewDidAppear.

ViewDidLoad runs only once, when UIViewController class is loading.

ViewDidAppear runs every time the UIViewController appears on screen.