问题描述
我的项目使用 SWRevealViewController.
我的问题是我可以在第一次点击 SWRevealView 切换按钮,但在我点击另一个视图控制器的返回按钮并返回后,该按钮不起作用到那个观点.
这是我的项目的屏幕截图.
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)
将导航控制器附加到详细视图控制器.服务和细节之间无需手动连接.添加返回事件的栏按钮.
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())
而不是在为 menubutton 添加目标的最后一行中添加您的代码.
Also add self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
instead of ur code in the lastline of adding target for menubutton.
检查这是否有效.
这篇关于在 Swift 中单击另一个 ViewController 的后退按钮后,SWRevealViewController 按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!