3

Hello i have integrated swrevealview controller in swift.

I have written below code in app delegate.

let frontView = ViewController(nibName: "ViewController", bundle: nil)
    let rearView = LeftViewController(nibName : "LeftViewController", bundle :nil)

    var frontNavigationController = UINavigationController(rootViewController: frontView)
    var rearNavigationController = UINavigationController(rootViewController: rearView)

    menuSlider = SWRevealViewController(rearViewController: rearNavigationController, frontViewController: frontNavigationController)
    menuSlider?.delegate = self

    let rightView = LeftViewController(nibName : "RightViewController", bundle :nil)

    menuSlider?.rightViewController = rightView

    self.window?.rootViewController = menuSlider
    self.window?.backgroundColor = UIColor.whiteColor()
    self.window?.makeKeyAndVisible()

On front view I have written

 var revealController:SWRevealViewController  = self.revealViewController()
    self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
    self.view.addGestureRecognizer(revealViewController().tapGestureRecognizer())

as shown in demo. I have seen lot's of posts suggesting adding gesture on views.

I am not sure what i am doing wrong. Please help me for solution.

Thanks

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Anil Kukadeja
  • 1,348
  • 1
  • 14
  • 27

2 Answers2

0

One thing I can think of is when it comes to your code, you are not storing strong references to the front, rear view controllers anywhere. It will basically be deallocated right after execution gets out of the method body. In your case, something like this would solve the problem:

Class myClass { 

    // Declaration
    var frontNC : UINavigationController!
    var rearNC : UINavigationController!

    ...
    func myFunction() {

       // Usage
       self.frontNC = UINavigationController(rootViewController: frontView)
       self.readNC = UINavigationController(rootViewController: rearView)

       // Note* there is no need to store ViewControllers because those
       // are retained by UINavigationController by default. The only
       // exception is if you want to do something with them later obviously :)
    }
}

While it will render, it creates whole set of problems and gesture recognizers are in my experience the worst one to track.

You can read more details on how ARC works in the Apple Documentation, I don't think anyone can explain it better than what is written there :)

Jiri Trecak
  • 5,092
  • 26
  • 37
0

Add following to your viewDidLoad method,

view.addGestureRecognizer(revealViewController().panGestureRecognizer())
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130