我有一个右栏按钮项(使用 SWReveal Controller ),我想使用显示“确定”的警报 View 注销,如果我单击“确定”弹出“取消”,它应该是 signet 并且必须导航到签名-在页面中,如果我点击“取消”,它应该保持不变......
我遇到了错误
这里是我的代码:
@IBAction func logoutButton(_ sender: Any) {
let alert = UIAlertController(title: "Alert", message: "Are you Sure You want to Logout", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("Please Enter Details")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
self.present(alert, animated: true, completion: nil)
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signOut()
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "signinpage") as! ViewController
self.navigationController?.pushViewController(secondViewController, animated: true)
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { action in
switch action.style{
case .default:
print("Please Enter Details")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}}))
self.present(alert, animated: true, completion: nil)
let secondViewController2 = self.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
self.navigationController?.pushViewController(secondViewController2, animated: true)
}
最佳答案
根据你的描述你需要
@IBAction func logoutButton(_ sender: Any) {
let alert = UIAlertController(title: "Alert", message: "Are you Sure You want to Logout", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
GIDSignIn.sharedInstance().signOut()
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "signinpage") as! ViewController
self.navigationController?.setViewControllers([secondViewController], animated: true)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler:nil))
self.present(alert, animated: true, completion: nil)
}
注销时最好使用 setViewControllers
而不是 popViewController
因为后者会在堆栈中留下旧的 vcs
关于ios - 如何使用警报 View 从登录身份验证中退出 Google,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56735296/