Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar mysteriously disappears in iOS 7

I started a project with Xcode 4, and today I updated my Xcode to 5. Running the same project in iOS7 simulator revealed some interesting (also frustrating) issues.

So my app has a sidebar that the user can tap on, and based on which button they tap on, I would instantiate a new VC using this code

YMGeneralInfoTableViewController *generalInfoTableVC = [self.storyboard instantiateViewControllerWithIdentifier:@"generalInfoTableVC"];

Then push this new VC onto the nav stack with this code

[self.navigationController pushViewController:generalInfoTableVC animated:YES];

Everything worked fine in iOS 6. However, in iOS7, the navbar magically disappears.

Here's a screen shot before pushing new VC enter image description here

Here is after pushing it: enter image description here

As you can see, there is a gap between where the content starts and the statusBar, in the position where the navBar should be.

I also tested out this code again on my iOS 6 device, everything is still fine on that iOS 6 device. So I am not sure what's going on here.

Also if I try to log the navBar/navigationItem of the controller where the navbar disappeared, I do get the correct reference to the navBar, which means that it is not nil, but simply not showing.

However, the methodsetHideNavigationBar:NO Animated:NO didn't bring the navBar back either. Does anyone know what's going on?

like image 880
Enzo Avatar asked Nov 11 '22 21:11

Enzo


1 Answers

By the way, I've found the solution for this.

It is because in AppDelegate, you might already set some of appearance changes for the Navigation Bar.

So what I suggest you to do is to check the device OS first before set custom apperance for Navigation Bar?

- (BOOL)isOS7
{
    float currentVersion = 7.0;

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < currentVersion)
        return NO;

    return YES;
}

So if return "NO" then only you do whatever possible that can be use for

like image 169
Keith Yeoh Avatar answered Nov 15 '22 05:11

Keith Yeoh