notes
notes copied to clipboard
iOS old rootViewController remains
- Set A as rootViewController
- A presents B (it is only a problem if present)
- Set C as rootViewController. Try to A.dismiss before
- A deinit
- We see C. But A view is behind, still there 😱
=> Change root view controller in dismiss completion block, even if the animated is false. Check for presentedViewController before dismiss
The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. The new content view is configured to track the window size, changing as the window size changes. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.
- http://stackoverflow.com/questions/17632024/changing-the-rootviewcontroller-of-a-uiwindow
- http://stackoverflow.com/questions/26795825/uiwindow-setrootviewcontroller-not-clearing-existing-hierarchy
An even simpler solution is to set the backgroundColor
of your new window to .white
or any color. The default is nil, which results in a transparent background. That is why the older window (on top of which the new one is made visible) is being seen through.