简体   繁体   中英

How to dismiss view controller after login Swift

I am trying to dismiss a view controller after the user has logged in successfully, but so far it is crashing in the Home view controller when I set tableView.delegate = self in viewDidLoad() . This is the code I use after a successful login:

self.view.window?.rootViewController = HomeVC()

This is the logic I have in SceneDelegate to present the login View Controller if the user is not signed in:

if(Auth.auth().currentUser == nil){
            window = UIWindow(frame: windowScene.coordinateSpace.bounds)
            window?.windowScene = windowScene
            window?.rootViewController = OnboardingVC()
        }

How can I dismiss the OnboardingVC after a successful login?

Here is the error log from the crash:

screen parameters are unexpected: MGScreenClass1125x2436x3x495 SCREEN_TYPE(1125,2436,3,495)

CUICatalog: Invalid asset name supplied: ''

Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file

This code will dismiss all the presented view controllers and remain root view controller:

self.view.window!.rootViewController?.dismiss(animated: false, completion: nil)

If you present the view using modal, try this:

self.dismiss(animated: true, completion: nil)

If you present the view using "push" segue, try this:

navigationController?.popViewController(animated: true)

dismiss(animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM