NavigationBar contents disappear on pop from view with prefersStatusBarHidden = YES - ios

I have a fairly straightforward setup in my iPhone app, with a navigation controller and a view controller. The view controller has a title, and for most of my views, pushing other view controllers works as expected: the title is used as the label for the "back" button on the navigation bar, and the new view is shown. After the new view has been popped from the stack, the old view is shown with its title.
However, as soon as the pushed view controller implements prefersStatusBarHidden with the return value YES, the title in the navigation bar is gone after this view is popped from the stack - it remains empty and doesn't even display my custom rightbarbuttonitem.
Additionally, doing this in landscape instead of portrait does not show this behaviour - the title is displayed correctly. If you encounter this issue in portrait, you could turn the phone to landscape and back to portrait again, and the title and everything else will reappear in place.
I am unsure if this was already there in previous versions of iOS, but I am currently seeing it with iOS 8.

I had the same issue and the workaround for me was this:
In the view controller that is having prefersStatusBarHidden set to YES add:
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
}

I believe that is because prefersStatusBarHidden is a app wide setting, not per view controller.
You may be able to get around this by adding to the pushed view controllers ViewWillDisappear method
- (void)viewWillDisappear:(BOOL)animated {
[UIApplication sharedApplication].statusBarHidden = NO;
}

Related

NavigationBar not appearing in second view controller

i am working on iPhone app.. i am using navigation controller, but the when i am going to the second view controller i.e. to the child view controller, the navigation bar is not appearing i had tried all the solutions around. Changing the property from translucent to inferred, vice-versa, tried doing it in code in viewDidLoad, viewDidAppear, viewWillAppear, everything..
Need some help..
In simulator it is showing and working perfectly but in device it isn't. I am using iphone 4s.
Check screenshot at below location:
http://postimg.org/image/y3nzz6t79/
I wanted to use below existing Back functionality - hence the transitions:
http://postimg.org/image/r2q34a4sr/
Try to embed your second view controller with Navigation Controller.
Set Top bar property to Opaque
Add this code in ViewDidAppear
[[self navigationController] setNavigationBarHidden:NO animated:YES];

Remove navigation bar from main controller in Xcode?

I have a main view controller in Xcode 6 (program is in swift) on which I have a few buttons that lead to certain navigation controllers. When I test the app, the first time I see it it looks fine (without a navigation bar at the top). When I click on a button on main view controller, it shows the navigation controller I selected, everything acts perfectly again. The problem happens when I click on the bar button "back" on that nav controller in order for it to show me my main view controller again. When I'm back to the main view controller, there's a navigation bar at the top that isn't supposed to be there. I want my main view controller to have no navigation bar at the top. I tried to use push, modal and show segues to see if it might be the problem, but I still can't figure it out. Any thoughts on what might be happening?
Sounds like you need to re-hide your navigation bar. To do that, add:
self.navigationController?.navigationBarHidden = true
to the viewWillAppear of whatever view controller for which you'd like to hide the nav bar.
Updated for Swift 3:
self.navigationController?.isNavigationBarHidden = true
In mainViewController, write code to hide navigation bar in viewWillAppear method.
in Objective-C
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}

Modal disappearing after rotating UISplitViewController

I have a strange problem UISplitViewController. I have a button in my master view controller which opens a modal view when tapped (using a simple storyboard segue).
But the modal view disappears when I rotate the iPad, but only when rotating from portrait to landscape. My master view controller is hidden in portrait, like in the native Mail application.
If I'm in landscape (when the master is always visible) and open my modal, rotating the device works correctly and my modal stays on screen.
I tried manually triggering the segue programmatically, if I call performSegueWithIdentifier: on the splitViewController, rotating works both ways. But I was wondering if this was fixable in a simpler way because I have other buttons displaying modals in the master view controller and I don't want to do an IB action for each one and lose the advantages of storyboard segues.
unfortunately it is like that, when your ipad is on portrait mode, you have a popover of your master, it is not the master in another shape. What means that you are presenting a modal using this popover as presentingViewController, so when you move from portrait to landscape the method splitViewController:willShowViewController will make your popover nil as you can see:
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
So I understand that is acceptable that your modal is going with it. So, with this you understand why when you put your action an call the performSegueWithIdentifier: on your splitViewController it doesn't happen, your modal is no longer connected with your popover.
So you may ask why it doesn't happen when you move from landscape to portrait.. and the reason is splitViewController:willHideViewController, it hides the viewController it doesn't remove it, so your modal is always connected.
So, unfortunately there is no solution and you will have to perform the actions by code..
I hope it helps,
Roberto

Navigation controller stack in landscape mode, but modally presented view controller view always in portrait frame size

My app mainly uses a navigation controller stack, and sometimes displays some controllers modally. In landscape mode the controllers within the nav controller stack work fine, but other view controller shown by presentViewController or previous presentModalViewController always give portrait size view frame (always 768x1024 on iPad iOS 6.0) - even when rotating back and forth between portrait and landscape.
Kind of related to A view controller is in landscape mode, but I'm getting the frame from portrait mode? however the checked answer is not helping. If I add the later view controller as part of the navigation stack the resize happening on first load and subsequent rotations work. The problem appears only, as stated above, when adding the controller by presentViewController.
wrap the modal branches to another nav controller and define the rotation mask there.
in iOS6 the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) works only on nav stack branches and entire branch should work the same way.
So, subclass the nav:
#interface CLNotRotatingNavController : UINavigationController
and in its .m add this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
return YES;
}
and wrap all the modal branches to this nav. This will lock everything to lanscape where necessary.

Popping in a UINavigationController inside a UISplitViewController causes strange transition

I am using a UINavigationController inside the Master View of a UISplitViewController. Inside of my UINavigationController I have, as usual, a UITableViewController. Selecting a cell in this table view pushes a new UINavigationItem onto the stack. This transition occurs as I expect. However, once I've pushed, when I push the Back button, the transition back to the top UINavigationItem doesn't slide from left to right as usual. Instead, the screen goes black, the Master View holding the UINavigationController/UITableViewController slides down in the center of the screen from the top, and then the UINavigationController appears back on the left side where I expect it. I've found similar questions, but all of the accepted answers revolve around not handling rotation correctly. I've double-checked that all of my view controllers return YES for all orientations.
implementing the following in my view controllers solved it for me
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Hope it works for you as well
You should check your implementation of - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation method in view controller that you have pushed into UINavigationController.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
// should return YES for all orientations
// or at least for orientation that your UINavigationController supports.
}
For me this issue appears only on iOS 5, but if you experience it on iOS 6 also, you could implement -(NSUInteger)supportedInterfaceOrientations in similar way.
I hope it will help you.

Resources