NavigationBar content disappears by default from view with prefersStatusBarHidden = YES

I have a pretty simple setup in my iPhone app with a navigation controller and a controller. The view controller has a heading, and for most of my views, clicking on other view controllers works as expected: the heading is used as a label for the back button in the navigation bar, and a new view is displayed. After the new view has been pushed out of the stack, the old view is displayed with its name.

However, as soon as the controller of the clicked view implements prefersStatusBarHidden with a return value of YES, the title in the navigation bar will disappear after this view pops out of the stack - it remains empty and does not even display my custom rightbarbuttonitem.

In addition, this behavior is not displayed in the landscape, but not in the portrait - the title is displayed correctly. If you encounter this problem in the portrait, you can switch the phone back to landscape and back to the portrait again, and the name and everything else will reappear in place.

I'm not sure if this was already in previous versions of iOS, but now I see it with iOS 8.

+5
source share
2 answers

I had the same problem and the workaround for me was as follows:

In the view controller whose prefersStatusBarHidden is set to YES, add:

- (void)viewWillDisappear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES]; [self.navigationController setNavigationBarHidden:NO]; } 
+4
source

I believe this is due to the fact that prefersStatusBarHidden is an application setup, and not for each view controller.

You may be able to get around this by adding the ViewWillDisappear method to the push-view controllers.

 - (void)viewWillDisappear:(BOOL)animated { [UIApplication sharedApplication].statusBarHidden = NO; } 
0
source

Source: https://habr.com/ru/post/1203745/


All Articles