I have a basic situation, when the user has been authenticated, I remove and change the current screen (the login screen) to another screen inside the app.
To do this, I use this code:
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
print("Window's subviews before removed = \(appDelegate.window?.subviews)")
appDelegate.window?.subviews.forEach { $0.removeFromSuperview() }
print("Window's subviews after removed = \(appDelegate.window?.subviews)")
appDelegate.window?.rootViewController?.view?.removeFromSuperview()
appDelegate.window?.rootViewController?.removeFromParentViewController()
appDelegate.window?.rootViewController = newRootViewController
print("Window's subviews after changed = \(appDelegate.window?.subviews)")
}
This is the output:
This is what the user can see on the device screen - looks very OK:
However, it isn't ok in the Debug View Hierarchy tool:
As you can see, the view of old rootViewController is still there, inside UIWindow
but not a subview of it - as the output has indicated.
This behavior seems strange, has anyone experienced this problem yet?