【发布时间】:2026-01-24 05:30:02
【问题描述】:
我是 Swift 新手,我正在尝试使用 SWrevealcontroller 实现侧边导航
我有一个根 VC,单击此按钮时有一个按钮,我正在导航到 UITabBarController
这是我的故事板的样子(下)
这就是我在按钮单击时导航的方式
@IBAction func clickButton(_ sender: Any) {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UITabBarController
self.present(nextViewController, animated:true, completion:nil)
}
这是我在FirstViewController中的代码
override func viewDidLoad() {
super.viewDidLoad()
barButton.target = self.revealViewController()
barButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
但是当我从根 VC 导航到 UITabBarController 时出现错误
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
Fatal error: Unexpectedly found nil while unwrapping an Optional value
谁能帮我看看这里出了什么问题。
TIA
【问题讨论】:
标签: ios swift swift4 swrevealviewcontroller