[英]Swift - pushing ViewController not working after presenting ViewController again
The question sounds a bit confusing but I don't know how to describe it better.. Let me explain:这个问题听起来有点令人困惑,但我不知道如何更好地描述它..让我解释一下:
The first ViewController
that gets presented is FirstLaunchVC
, where he user types in his email and if he is registered he get's to LoginVC
and from there he get's to MainVC
.出现的第一个ViewController
是FirstLaunchVC
,用户在其中输入他的电子邮件,如果他已注册,他将进入LoginVC
然后从那里进入MainVC
。 Everything is working fine.一切正常。
In MainVC
the user can sign out and get's back to FirstLaunchVC
.在MainVC
,用户可以退出并返回FirstLaunchVC
。 However, after doing the weiterButton
which should bring the user to LoginVC
is not doing anything.但是,在执行了应该将用户带到LoginVC
的weiterButton
之后,它并没有做任何事情。
FirstLaunchVC:首次启动VC:
@objc func weiterButtonTapped() {
email = emailTextfield.text!.trimmingCharacters(in: .whitespacesAndNewlines)
//prüfen, ob Email schon registriert ist
Auth.auth().fetchSignInMethods(forEmail: email) { (methods, error) in
//Email ist noch nicht registriert -> sign up
if methods == nil {
let SignUpView = self.storyboard?.instantiateViewController(withIdentifier: "SignUpVC") as! SignUpViewController
SignUpView.email = self.email
self.navigationController?.pushViewController(SignUpView, animated: false)
}
//Email ist registriert -> login
else {
print("hi")
self.view.endEditing(true)
let LoginView = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC") as! LoginViewController
LoginView.email = self.email
self.navigationController?.pushViewController(LoginView, animated: true)
}
}
}
Main Problem:主要问题:
The print(hi)
is printing but pushViewController
is not working after signing out. print(hi)
正在打印,但退出后pushViewController
不起作用。
LoginVC:登录VC:
func transitionToHome () {
let homeVC =
storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.homeViewController) as? MainViewController
let navigationController = UINavigationController(rootViewController: homeVC!)
view.window?.rootViewController = navigationController
view.window?.makeKeyAndVisible()
}
MainVC:主VC:
This is where the user can sign out.这是用户可以退出的地方。
@objc func signoutButtonTapped() {
UserDefaults.standard.setIsLoggedIn(value: false)
UserDefaults.standard.synchronize()
let firstLaunchVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstLaunchVC")
self.navigationController?.present(firstLaunchVC, animated: true)
}
I tried to explain the problem the best I can.我试图尽我所能解释这个问题。 If anything is still unclear just let me know.如果还有什么不清楚的,请告诉我。 I am happy for any help :)我很高兴得到任何帮助:)
if after sign out weiterButtonTapped() called,如果注销后调用weiterButtonTapped(),
you should put your pushController line in dispatch that's because controller be fully deallocated:你应该把你的 pushController 行放在 dispatch 中,因为控制器被完全释放:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.navigationController?.pushViewController(LoginView, animated: true)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.