Ios SWRevealViewController在展开可选值时意外发现nil
您好,在用户单击UIAlertView上的ok操作按钮后,我正在将用户重定向到其他控制器Ios SWRevealViewController在展开可选值时意外发现nil,ios,swift,swrevealviewcontroller,Ios,Swift,Swrevealviewcontroller,您好,在用户单击UIAlertView上的ok操作按钮后,我正在将用户重定向到其他控制器 let successAlert = UIAlertController(title: "Success", message: Message.TRIPISLIVE, preferredStyle: UIAlertControllerStyle.Alert) let action = UIAlertAction(title: "OK", style: .Default)
let successAlert = UIAlertController(title: "Success", message: Message.TRIPISLIVE, preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
let viewControllerYouWantToPresent = self.storyboard?.instantiateViewControllerWithIdentifier("MyTripsTableViewController")
self.presentViewController(viewControllerYouWantToPresent!, animated: true, completion: nil)
}
successAlert.addAction(action)
self.presentViewController(successAlert, animated: true, completion: nil)
单击“确定”后,我在重定向的secondViewController中遇到错误
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
if revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
错误是致命错误:在展开可选值时意外发现为零您是否可以尝试此操作,而不是
视图的代码将出现
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
if revealViewController() != nil {
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
编辑
您可以在viewController
func customLeftButtonAction() {
self.revealViewController().revealToggleAnimated(true);
}
然后修改
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated);
if revealViewController() != nil {
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
menuButton.target = self
menuButton.action = #selector(self.customLeftButtonAction)
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
编辑
您必须修改显示您的viewcontrolleryyouwanttopresent
的表单,因此请使用此代码
let successAlert = UIAlertController(title: "Success", message: Message.TRIPISLIVE, preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
let viewControllerYouWantToPresent = self.storyboard?.instantiateViewControllerWithIdentifier("MyTripsTableViewController")
self.revealViewController().setFrontViewController(viewControllerYouWantToPresent!, animated: false);
self.revealViewController().revealToggleAnimated(true);
}
successAlert.addAction(action)
self.presentViewController(successAlert, animated: true, completion: nil)
我希望这对你有帮助是的,很有效,谢谢。。但问题是现在菜单汉堡按钮在这个控制器上不再工作了。你能写一个完整的代码或编辑我的吗。我是新来的,所以不明白我应该写些什么检查一下,我希望这能帮助你谢谢你。。。我应该在这里写什么?menuButton.action=#选择器(self.customLeftButtonAction)让我们来看看。