我正在使用SWRevealViewController在Swift 2.0中显示侧面菜单我已经从GitHub下载了文件,创建了桥接头并正确连接了segue。我正在创建一个自定义按钮但是动作“显示切换”并未触发。我在哪里弄错了?
super.viewDidLoad()
self.navigationController?.navigationBar.topItem?.title = "DASHBOARD"
self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()
self.navigationController!.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController!.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Teko-Regular", size: 26)!]
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
let btnName = UIButton()
btnName.setImage(UIImage(named: "LeftNavItem"), forState: .Normal)
btnName.frame = CGRectMake(0, 0, 20, 20)
let leftBarButton = UIBarButtonItem()
leftBarButton.customView = btnName
self.navigationItem.leftBarButtonItem = leftBarButton
if self.revealViewController() != nil {
//print(self.revealViewController())
leftBarButton.target = self.revealViewController()
leftBarButton.action = Selector("revealToggle:")
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
手势识别器正在正常发射,但不是“revealToggle:”这是什么错误?
答案 0 :(得分:1)
holder.itemName.setText(list.get(position));
答案 1 :(得分:0)
我使用SWRevealViewController遇到了同样的问题。 解决方案:**登录后,我之前调用了仪表板屏幕 我替换为SWrevealviewcontroller,如下面的代码。它现在正常工作
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController1 =
storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
self.present(viewController1, animated: true,completion: nil)
*在viewdidload()方法中添加以下代码
if revealViewController() != nil {
menuoutlet.target = self.revealViewController()
menuoutlet.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
self.revealViewController().rearViewRevealWidth = 240
}
菜单按钮操作代码
@IBAction func menu(_ sender: Any) {
let btntitle = (sender as AnyObject).currentTitle!
self.revealViewController().rearViewController.performSegue(withIdentifier: btntitle!, sender: self.revealViewController().rearViewController)
}