У меня есть элемент кнопки правой панели (с использованием контроллера SWReveal), и я хочу выйти из системы, используя представление предупреждений, показывающее всплывающие окна «ОК» и «Отмена», если я нажимаю «ОК», он должен подписать и должен перейти на страницу входа и если я нажму «Отмена», он останется прежним .......
я получаю ошибки
вот мой код:
@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 в стеке.