For the life of me, I can't figure why.
I'm displaying a UIAlertController on a UIViewController embedded in a UINavigationController.
The navigation bar has a dark color, so I made the navigation bar's style black so that the text would appear white. Apparently overriding preferredStatusBarStyle does not work when a UIViewController is embedded in a UINavigationController, because the latter does not pass the configuration on to its children.
Because the default behavior / appearance of the navigation bar currently is that its background does not extend to cover the status bar, I set the appearnce myself in the UIViewController's viewDidLoad() method.
Now, everything is working as it should. The navigation bar has a dark background and a white text, and all is well and good.
Until I presented a UIAlertController with a default action and dismissed it with the button, that is. Now, for some reason, the status bar's text reverted back to being black.
I don't understand what's happening. I tried setting modalPresentationCapturesStatusBarStyle to true on the "host" UIViewController, but that only made the status bar black while the alert was open, and it stayed that way when it was dismissed.
I tried presenting a modal on a UIViewController not embedded in a UINavigationController, but it didn't face the issue. The status bar was white all the way through, so I conclude it has something to do with the UIViewController being embedded.
I read somewhere that the issue got resolved by setting the root viewController for the UINavigationController explicitly, but no accompanying code as to how that should be done.
Any ideas as to what I should do to make it stay white? And sorry for the long post. I thought I should mention all I've tried and concluded.