Deinit UITabBarController after presenting new ViewController

1.1k views Asked by At

I have an app in which users can log in. If the user launches the app and is already logged in then the rootViewController is set to my custom UITabBarController but when the user is not logged in the rootViewController is set to LoginVC (View Controller). My problem is that when the user logs out the LoginVC should be presented and the TabBar should be deinitialized.

I have tried:

self.tabBarController?.dismiss(animated: true, completion: {
    self.tabBarController?.present(LoginVC(), animated: true, completion: nil)
})

And things like that... I can present the LoginVC but when I call self.tabBarController?.dismiss the LoginVC gets dismissed instead of the TabBarVC

Any help would be greatly appreciated

1

There are 1 answers

2
Lou Franco On BEST ANSWER

It's better to just set the rootViewController to the LoginVC. The reference to the UITabBarController will be lost and it will de-init.

Calling dismiss on a VC does not dismiss that VC. It dismisses the VC it is presenting:

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621505-dismiss

Dismisses the view controller that was presented modally by the view controller.