What happens to a View Controller after it has modally presented another View Controller

66 views Asked by At

Consider the following structure of an app:

Login Screen --> Splash Screen --> Main use (--> Logout page --> New Instance of Login Screen)

When the user logs in from the Splash Screen, I present the Splash Screen Modally from the Login Screen. When the Splash Screen have completed it's tasks, I present the Main Use View (Which is a UITabController) modally from the Splash Screen. If at some point the user decides to logout of the app, I remove the credentials and present a new Instance of the Login Screen modally from the Main Use View.

I recently started doubting that this works as I expect it to. Say that the user have navigated all the way to Main Use, are the presenting View Controller (Splash Screen) and it's presenting View Controller (Login Screen) still active and present in the Hierarchy? After Modally presenting another View Controller, I expect the first View Controller to be completely unloaded and forgotten by the System, as if it was set to null. Can someone confirm this? And in case this doesn't work as I expect it to, what should I do instead of modally presenting View Controllers?

1

There are 1 answers

2
Duncan C On

Your doubts are warranted. When you present a modal view controller, it goes on top of the existing view controller and covers it, but the existing view controller does not go away. You never want to present a new copy of a view controller without dismissing the previous one. (Using dismiss(animated:completion:).)