John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 987 forks source link

viewcontroller is nil #790

Closed aksh1995a closed 6 years ago

aksh1995a commented 6 years ago

hello I am integrating swreveal to my swift project

and my vc is returning nil

if (self.revealViewController() == nil){ let button1 = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(self.back)) self.navigationItem.leftBarButtonItem = button1 self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.barTintColor = UIColor(red: 1.00, green: 1.00, blue: 1.00, alpha: 1) self.navigationController?.navigationBar.isTranslucent = true

   // self.navigationItem.leftBarButtonItem = barButton
   // self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    //self.revealViewController().rearViewRevealWidth = 200
   // self.revealViewController().panGestureRecognizer().isEnabled=true

    }
    else
    {
        print("nil nil nil nil")
    }

so I am not getting the back button and reveal is blocked

and I removed the condition and changed its width to

    self.revealViewController().rearViewRevealWidth = 200

img_0006

can u help me out why am I not getting my root view on the side instead a black view

aksh1995a commented 6 years ago

and my root vc has a collection view so subclass of colviewcontroller and flowlayoutdele and I am not using storyboard

iDevelopper commented 6 years ago

Can you check your test?

if (self.revealViewController() == nil){

It should be:

if (self.revealViewController() != nil){

aksh1995a commented 6 years ago

yes it was going to else block I wanted to see what happens when the code runs so I changed the condition

aksh1995a commented 6 years ago

should our home vc be necessarily a subclass of swreveal??

iDevelopper commented 6 years ago

Your home vc must be the front view controller of SW.

aksh1995a commented 6 years ago

if self.revealViewController() != nil {

    let button1 = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(SWRevealViewController.revealToggle(_:)))
    self.navigationItem.leftBarButtonItem  = button1
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.barTintColor  = UIColor(red: 1.00, green: 1.00, blue: 1.00, alpha: 1)
    self.navigationController?.navigationBar.isTranslucent = true
        button1.target = self.revealViewController()
        button1.action = #selector(SWRevealViewController.revealToggle(_:))
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }
    else
    {
        print("swreveal nil")
    }

I am getting swreveal nil in log why am I getting nil any idea?? now my class is a subclass of swreveal

aksh1995a commented 6 years ago

sorry I found the issue in app delegate I set my root vc to sw now it returned non nil works fine!!Thanks