你好,在用户单击 UIAlertView 上的 ok 操作按钮后,我将用户重定向到其他 Controller 。
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())
}
}
错误是 fatal error :在展开可选值时意外发现 nil
最佳答案
你能试试这个而不是你的 viewWillAppear
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())
}
}
EDITED
你可以在你的viewController
上添加一个func
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())
}
}
Edited
您必须修改您呈现viewControllerYouWantToPresent
的表单,所以将此代码改为
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)
希望对你有帮助
关于ios - SWRevealViewController 在解包 Optional 值时意外发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37867468/