我有一个允许用户注销的按钮,一旦用户选择了这个按钮(“signoutButton”),就会出现一个UIAlertController,询问用户是否想注销。
我有一个用户退出的代码和弹出的代码。但是,一旦用户选择“Ok”,我正在寻找一种运行‘signOut’函数的方法。有什么想法吗?
当前的注销方法(用户单击“注销”按钮,将其签出并重定向到主视图控制器)
@IBAction func signoutButton(_ sender: Any) {
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
self.transitionToHome()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
}我有这条弹出消息(但是,我希望它是分开的,所以一旦用户选择了‘Ok’按钮,它们就会被签出来并带到主视图控制器上)。
let alert = UIAlertController(title: "Logout", message: "You have been sucessfully logged out, bye!", preferredStyle: UIAlertController.Style.alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
func transitionToHome() {
let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
view.window?.rootViewController = homeViewController
view.window?.makeKeyAndVisible()
}对我怎么做有什么想法吗?
发布于 2020-12-01 20:13:07
您只需要将签名和转换调用放到按钮处理程序中,如下所示:
@IBAction func signoutButton(_ sender: Any) {
let alert = UIAlertController(title: "Logout", message: "You have been sucessfully logged out, bye!", preferredStyle: .alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: .default) { action in
do {
try Auth.auth().signOut()
self.transitionToHome()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
})
// show the alert
self.present(alert, animated: true, completion: nil)
}https://stackoverflow.com/questions/65097601
复制相似问题