【发布时间】:2016-04-26 10:36:21
【问题描述】:
我有一个名为 login VC 的视图控制器和导航视图控制器。我在我的 LoginVc 中连接了两个按钮。第一个按钮将导航到注册屏幕作为推送序列。第二个按钮将导航到忘记密码屏幕作为推送序列。
现在,当用户登录并进入我的应用程序时。有一个名为注销的按钮名称。我已经编写了代码功能,例如,当用户按下注销按钮时,一个 uialert 弹出窗口会询问“你想要注销”。如果用户按下,他们将导航到再次登录屏幕。
所以在用户按下注销后,如果用户进入登录屏幕,如果用户按下我的两个按钮 [ i. e表示忘记密码屏幕,注册屏幕按钮]。然后我崩溃了。
崩溃报告:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
我的注销按钮代码:
@IBAction func LogoutButton(sender: AnyObject) {
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "ISLOGGEDIN")
NSUserDefaults.standardUserDefaults().synchronize()
dispatch_async(dispatch_get_main_queue(), {
let alert = UIAlertController(title: "Logout Successful", message: "You have successfully logged out.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){action -> Void in
let loginViewController = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as? LoginViewController
let appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = loginViewController
})
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
})
}
我尝试添加这一行:
let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("LoginViewController") as! UINavigationController
但我遇到了同样的问题。现在如何在注销按钮操作方法中重新编写代码。使用导航栏重定向到登录屏幕。
请帮帮我。谢谢!
【问题讨论】: