簡體   English   中英

Swift - 再次呈現 ViewController 后,推動 ViewController 不起作用

[英]Swift - pushing ViewController not working after presenting ViewController again

這個問題聽起來有點令人困惑,但我不知道如何更好地描述它..讓我解釋一下:

出現的第一個ViewControllerFirstLaunchVC ,用戶在其中輸入他的電子郵件,如果他已注冊,他將進入LoginVC然后從那里進入MainVC 一切正常。

MainVC ,用戶可以退出並返回FirstLaunchVC 但是,在執行了應該將用戶帶到LoginVCweiterButton之后,它並沒有做任何事情。

首次啟動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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM