简体   繁体   English

Swift - 再次呈现 ViewController 后,推动 ViewController 不起作用

[英]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 .出现的第一个ViewControllerFirstLaunchVC ,用户在其中输入他的电子邮件,如果他已注册,他将进入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.但是,在执行了应该将用户带到LoginVCweiterButton之后,它并没有做任何事情。

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.

相关问题 在使用Swift展示新的Viewcontroller后如何关闭以前的Viewcontroller? - How to dismiss previous Viewcontroller after presenting new Viewcontroller using Swift? 在关闭当前ViewController之后快速显示,然后Presenting ViewController不调用viewWillAppear() - Swift after dismiss Current ViewController then the Presenting ViewController not calling viewWillAppear() Swift 在呈现新的 ViewController 后关闭当前的 ViewController - Swift dismiss current Viewcontroller after presenting new ViewController 使用NavigationViewController swift呈现ViewController - presenting ViewController with NavigationViewController swift 向viewController进行过渡无法正常工作 - Presenting viewController with transition is not working 在 swift 中获取 viewController.view 的呈现视图控制器 - Get the presenting viewController of viewController.view in swift Swift iOS -NSMutableAttributedString不呈现ViewController吗? - Swift iOS -NSMutableAttributedString Not Presenting ViewController? Swift:通过UITabBarController呈现一个viewController - Swift: Presenting a viewController over UITabBarController 在 swift 中呈现自定义 ViewController class? - Presenting custom ViewController class in swift? iOS推动ViewController无法正常工作 - iOS Pushing a ViewController not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM