![](/img/trans.png)
[英]How to dismiss previous Viewcontroller after presenting new Viewcontroller using Swift?
[英]Swift - pushing ViewController not working after presenting ViewController again
這個問題聽起來有點令人困惑,但我不知道如何更好地描述它..讓我解釋一下:
出現的第一個ViewController
是FirstLaunchVC
,用戶在其中輸入他的電子郵件,如果他已注冊,他將進入LoginVC
然后從那里進入MainVC
。 一切正常。
在MainVC
,用戶可以退出並返回FirstLaunchVC
。 但是,在執行了應該將用戶帶到LoginVC
的weiterButton
之后,它並沒有做任何事情。
首次啟動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)
}
}
}
主要問題:
print(hi)
正在打印,但退出后pushViewController
不起作用。
登錄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()
}
主VC:
這是用戶可以退出的地方。
@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)
}
我試圖盡我所能解釋這個問題。 如果還有什么不清楚的,請告訴我。 我很高興得到任何幫助:)
如果注銷后調用weiterButtonTapped(),
你應該把你的 pushController 行放在 dispatch 中,因為控制器被完全釋放:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.navigationController?.pushViewController(LoginView, animated: true)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.