preferredStatusBarStyle isn't called
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When preferredStatusBarStyle is not being called, the problem is usually not the method itself. The problem is that the wrong view controller owns status bar appearance, or the app is configured to manage the status bar globally instead of per controller.
The fix is usually one of three things: enable controller-based status bar appearance, ask the correct container controller to forward the request, or call setNeedsStatusBarAppearanceUpdate() at the right time.
Make Sure View Controllers Control the Status Bar
First check Info.plist. If UIViewControllerBasedStatusBarAppearance is disabled, your individual view controller's override may never matter.
The usual working setup is:
With that in place, a normal override looks like this:
If the method still is not called, the next thing to inspect is the controller hierarchy.
Container Controllers Often Own the Decision
If your screen is inside a UINavigationController, UITabBarController, or another container, the container may be the one asked about the status bar style.
A common fix is to forward the style request to the visible child:
Now the top view controller gets to decide its own style.
Without this forwarding behavior, you can override preferredStatusBarStyle in your child controller all day and still never see it used.
Trigger an Update When the Style Changes
If the desired status bar style changes after the controller is already on screen, tell UIKit to ask again:
You may also call it after theme changes, modal presentation changes, or navigation transitions that affect the background behind the status bar.
The key point is that UIKit does not constantly poll preferredStatusBarStyle. It checks when appearance needs to be updated.
A Full Working Example
This setup covers the most common navigation-controller case.
Other Situations to Check
A few other things can interfere:
- a modal controller presented over the top
- a custom container that never forwards status bar questions
- trying to use the old application-wide status bar APIs
- assuming the root controller and visible controller are the same thing
On modern iOS, the container hierarchy matters a lot more than many older tutorials suggest.
Scene-based apps do not change this core rule. Even with newer lifecycle APIs, UIKit still asks the currently responsible controller hierarchy for the status bar style.
Common Pitfalls
- Setting
UIViewControllerBasedStatusBarAppearanceincorrectly inInfo.plist. - Overriding
preferredStatusBarStylein a child controller while the navigation controller actually owns the decision. - Forgetting to call
setNeedsStatusBarAppearanceUpdate()when the desired style changes dynamically. - Debugging the visible controller while a presented controller is actually in charge.
- Mixing old global status bar techniques with modern controller-based appearance rules.
Summary
- If
preferredStatusBarStyleis not called, check ownership before checking syntax. - Controller-based status bar appearance should be enabled in
Info.plist. - Navigation and tab bar controllers often need to forward the decision to the active child.
- Call
setNeedsStatusBarAppearanceUpdate()when the style changes after presentation. - In most cases, the bug is really about controller hierarchy, not about the override itself.
Related reading
- Present and dismiss modal view controller
- Presenting a UIAlertController properly on an iPad using iOS 8
- Presenting modal in iOS 13 fullscreen
- presenting ViewController with NavigationViewController swift
- presenting ViewController with NavigationViewController swift
- presentViewController and displaying navigation bar
- presentViewController crash on iOS 6 AutoLayout
- presentViewControlleranimatedYES view will not appear until user taps again
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.