SWRevealViewController button not work after clicking Back button from another ViewController in Swift

女生的网名这么多〃 提交于 2019-11-27 08:36:38

问题


I use SWRevealViewController for my project.
My problem is that I can click on the SWRevealView Toggle button at first time and that button does not work after I click on Back button from another view controller and back to that view.
Here is the screenshot of my project.


I click on NavigationLeft button from Service View Controller at first and left menu shows up.
After that, I click on "Imageview" from that view controller to go to next page.
When I reached to detailed next page, I click on "Back button" and it goes to Service view controller.
At that time , I click on RevealView Toggle button , it does not work. I got error fatal error: unexpectedly found nil while unwrapping an Optional value.


My codes from Service View Controllers are;

 override func viewDidLoad() {
    super.viewDidLoad()

 if self.revealViewController() != nil {
        debugPrint("Menu Click")
        btnBack.target = self.revealViewController()
        btnBack.action = #selector(SWRevealViewController.revealToggle(_:))
        self.revealViewController().panGestureRecognizer()

    }

    else
    {
        debugPrint("nil")
        btnBack.target = self.revealViewController()
        btnBack.action = #selector(SWRevealViewController.revealToggle(_:))
        // self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        self.revealViewController().panGestureRecognizer()

    }


}

When the project runs first time, the code passes to "self.revealViewController() != nil" and I go to detailed view controller and click on Back button. At that time the code passes to " debugPrint("nil")" and it does not show up menu or work.

Codes from Detailed view controller are;

 @IBAction func btnBack(_ sender: UIBarButtonItem) {
    debugPrint("BtnBack")
    self.dismiss(animated: true, completion:nil)

}

Is my code is something wrong or logic wrong ? I have been trying to solve this problem since one week. Please help me ..


回答1:


On click event of image view in serviceViewController,

let detailVC = self.storyboard?.instantiateViewController(withIdentifier: "Detail") as! DetailVc
    self.navigationController?.pushViewController(detailVC, animated: true)

Attach a navigation controller to detail viewcontroller. No need for manual connection between service and detail. Add a barbutton for goingback event.

 self.navigationController?.popViewController(animated: true)

Also add self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer()) instead of ur code in the lastline of adding target for menubutton.

Check whether this works.



来源:https://stackoverflow.com/questions/42573338/swrevealviewcontroller-button-not-work-after-clicking-back-button-from-another-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!