Tried everything. Just trying to hide it for one view controller.
.plist:
Status bar is initially hidden = NO
View controller-based status bar appearance = YES
view controller:
- (BOOL)prefersStatusBarHidden {
return YES;
}
//I shouldn't have to do this, the above method should suffice. Doesn't work anyway
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Nothing works. Status bar is still there, staring me in the face, laughing through it's ugliness. What do I need to do???
EDIT: prefersStatusBarHidden
does not even get called. This view controller is pushed onto the navigation stack via push segue.
The key here was that this was never getting called in the view controller:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Tracing backward, it was not called in the parent navigation controller either. This is because the nav controller was owned by a root view controller. The root view controller did call this method, but did not pass it on to the nav controller, and thus not to any other child view controllers. So for anyone having the same issue and trying to debug, try to track down the view controller at the "root" of your hierarchy.
So in my case, I post a notification from any view controller (viewWillAppear
) that I want to hide the status bar. This notification is then consumed by the root controller:
- (void)hideStatusBar:(NSNotification *)notification {
self.hideStatusBar = YES;
[self setNeedsStatusBarAppearanceUpdate];
}
Which forces this method to be called on the root controller:
- (BOOL)prefersStatusBarHidden {
return self.hideStatusBar;
}
And everything works as expected. The same can be done for showing the status bar again.