如何在使用 Firebase 成功验证后以编程方式继续?
How to programmatically segue after successful authentication with Firebase?
我刚开始使用 Swift 编写代码,我需要帮助!
我通过电子邮件对 firebase 进行了身份验证,我希望在登录后显示另一个视图控制器,我很困惑,因为我不知道在这种情况下如何使用 prepare to segue。我需要在哪里添加以及如何添加。
谢谢
我的代码在这里。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let lvc = storyboard?.instantiateViewController(withIdentifier: "homeViewController") as? homeViewController
self.navigationController?.pushViewController(lvc!, animated: true)
}
@objc private func didTapButton() {
print("Continue Button Password")
guard let email = emailField.text, !email.isEmpty,
let password = passwordField.text, !password.isEmpty else {
print("Missing field data")
return
}
FirebaseAuth.Auth.auth().signIn(withEmail: email, password: password, completion: { [weak self] result, error in
guard let strongSelf = self else {
return
}
// guard error == nil else {
// //show account creation
// strongSelf.showCreateAccount(email: email, password: password)
// return
// }
print("You have signed in")
strongSelf.label.isHidden = true
strongSelf.emailField.isHidden = true
strongSelf.passwordField.isHidden = true
strongSelf.Button.isHidden = true
strongSelf.emailField.resignFirstResponder()
strongSelf.passwordField.resignFirstResponder()
})
}
prepare(for:sender:)
不正确。该方法用于将数据传递给 segue.destination
视图控制器,而不是用于启动推送或其他任何操作。例如,如果你的目标视图控制器是一个 FooViewController
并且你想设置 bar
属性 以便将一些数据从当前视图控制器传递到 FooViewController
,你会:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? FooViewController {
destination.bar = ...
}
}
但是如果您不需要将任何数据传递给目标视图控制器,则不需要 prepare(for:sender:)
。
在回答标题问题时,如果你的故事板有一个转场,给那个转场一个标识符,然后以编程方式启动它,你会这样做:
storyboard?.performSegue(withIdentifier: "xxx", sender: self)
我刚开始使用 Swift 编写代码,我需要帮助! 我通过电子邮件对 firebase 进行了身份验证,我希望在登录后显示另一个视图控制器,我很困惑,因为我不知道在这种情况下如何使用 prepare to segue。我需要在哪里添加以及如何添加。
谢谢
我的代码在这里。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let lvc = storyboard?.instantiateViewController(withIdentifier: "homeViewController") as? homeViewController
self.navigationController?.pushViewController(lvc!, animated: true)
}
@objc private func didTapButton() {
print("Continue Button Password")
guard let email = emailField.text, !email.isEmpty,
let password = passwordField.text, !password.isEmpty else {
print("Missing field data")
return
}
FirebaseAuth.Auth.auth().signIn(withEmail: email, password: password, completion: { [weak self] result, error in
guard let strongSelf = self else {
return
}
// guard error == nil else {
// //show account creation
// strongSelf.showCreateAccount(email: email, password: password)
// return
// }
print("You have signed in")
strongSelf.label.isHidden = true
strongSelf.emailField.isHidden = true
strongSelf.passwordField.isHidden = true
strongSelf.Button.isHidden = true
strongSelf.emailField.resignFirstResponder()
strongSelf.passwordField.resignFirstResponder()
})
}
prepare(for:sender:)
不正确。该方法用于将数据传递给 segue.destination
视图控制器,而不是用于启动推送或其他任何操作。例如,如果你的目标视图控制器是一个 FooViewController
并且你想设置 bar
属性 以便将一些数据从当前视图控制器传递到 FooViewController
,你会:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? FooViewController {
destination.bar = ...
}
}
但是如果您不需要将任何数据传递给目标视图控制器,则不需要 prepare(for:sender:)
。
在回答标题问题时,如果你的故事板有一个转场,给那个转场一个标识符,然后以编程方式启动它,你会这样做:
storyboard?.performSegue(withIdentifier: "xxx", sender: self)