在Swift中从另一个ViewController单击Back按钮后,SWRevealViewController按钮不起作用 [英] SWRevealViewController button not work after clicking Back button from another ViewController in Swift

查看:123
本文介绍了在Swift中从另一个ViewController单击Back按钮后,SWRevealViewController按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将SWRevealViewController用于我的项目.
我的问题是,我可以第一次单击 SWRevealView Toggle按钮,并且在我从另一个视图控制器上单击后退"按钮并返回后,该按钮不起作用到那个观点.
这是我的项目的屏幕截图.


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.


我首先从Service View Controller中单击NavigationLeft按钮,然后显示左侧菜单.
之后,我从该视图控制器中单击"Imageview"以转到下一页.
当我到达详细的下一页时,我单击后退按钮",然后转到服务视图控制器.
当时,我单击RevealView Toggle按钮,它不起作用.我收到错误致命错误:在展开可选值时意外发现nil .


我来自 Service View Controllers 的代码是;

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()

    }


}

当项目第一次运行时,代码将传递到"self.revealViewController()!= nil",然后转到详细的视图控制器,然后单击上一步"按钮.那时,代码传递给"debugPrint("nil"),并且它不显示菜单或工作.

详细视图控制器中的代码是;

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 ..

推荐答案

在serviceViewController中图像视图的单击事件上,

On click event of image view in serviceViewController,

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

将导航控制器附加到详细视图控制器.无需在服务和细节之间进行手动连接. 添加回退事件的barbutton.

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)

还要在添加菜单按钮目标的最后一行中添加self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())而不是您的代码.

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

检查是否可行.

这篇关于在Swift中从另一个ViewController单击Back按钮后,SWRevealViewController按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆