UINavigationBar mysteriously disappears in iOS 7 - ios

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
Here is after pushing it:
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?

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

Checkout Autolayout constraints,
I have tried same by using iOS 6 and iOS 7, my navigation bar is showing. Still checkout Autolayout constraints, i have doen it without autolayout

Related

iOS broken auto layout on simulator 7.1 after segue (works on ios 8)

I have very strange problem on ios simulator 7.1 with auto layout but on ios 8 everything works fine.
On ios simulator 7.1 when new "View Controller" was presented through segue its content becomes layout incorrectly and sometimes even moves.
Demo code on github:
https://github.com/Misterio26/iOS-7-Simulator-Bug-demo
This demo uses only interface builder, there's no hand code at all, that is why I very surprised about this bug.
To reproduce:
use xCode 6
run with ios simulator (7.1)
press "Works", you will see a test screen that is aligned correctly (sometimes not), then press "Back"
press "Bug", after screen appearance you will notice some ui movement and incorrect alignment (sometimes it shows constraints error in console log)
I log window.hasAmbiguousLayout in viewDidAppear, and it print "false" for iOS 8 and "true" for iOS 7. Looks like iOS7 creates wrong constraints for presenting view controller. I used "po [[UIWindow keyWindow] _autolayoutTrace];" and it confirmed my suggestion.
I can't belive that only I have noticed this problem.
Can someone help me to know:
Is it simulator bug or it happens on real device too? (I don't have ios 7 device, just 8, and apple doesn't allow to downgrade ios)
Or maybe it can be fixed?
Or you can only try to reproduce that window.hasAmbiguousLayout becomes "true" after segue (I think that it's very dangerous bug):
create new iOS project in XCode6
in IB create new View Controller with one button
in IB create second View Controller with any content
in IB create "show" segue from button to second view controller (command + drag from button to second view controller)
in CODE create new class #interface CustomViewController : UIViewController
in CODE add to CustomViewController
- (void)viewDidAppear:(BOOL)animated {
UIWindow* window = [UIApplication sharedApplication].keyWindow;
NSLog(#"viewDidAppear hasAmbiguousLayout %#", ([window hasAmbiguousLayout] ? #"true" : #"false"));
}
in IB apply class CustomViewController to second view controller
run on ios 8 and you will see "viewDidAppear hasAmbiguousLayout false"
run on ios simulator 7.1 and you'll see "viewDidAppear hasAmbiguousLayout true"
I think it's very dangerous behavior.

Status bar rotates but application does not, on iPhone- works fine on iPad?

Long time lurker, always tried very hard to search and have found many answers this way. This is the first time I have found nothing that fixes my problem. This is also my first solo app, as I am a new developer.
I have two devices- an iOS 8.1 iPhone 6, and an iOS 7 iPad Mini Retina 2.
I am building my first iOS app. It uses storyboards for a UITabBarController with three tabs, each of which contains a UINavigationController and a custom sub view controller (such as a subclass of tabbarcontroller or collectionviewcontroller).
Under Deployment Info:
Deployment Target is set to 7.0 and Universal. iPhone and iPad both use the MainStoryboard main interface, with all four Device Orientations checked for both.
My AppDelegate starts with:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UITabBarController *initViewController = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:#"rootTabBarController"];
NSLog(#"%d %d",initViewController.shouldAutorotate,initViewController.shouldAutomaticallyForwardRotationMethods);
[self.window setRootViewController:initViewController];
Note the NSLog; it prints "1 0".
So from what I can see- the tab bar should auto rotate.
On my iPhone, when I turn the device sideways, the status bar on the top rotates- but the content remains upright. If I hit the Home button and switch back to the app while holding it sideways, everything goes wonky- the content rotates but doesn't rearrange the layout, so it remains vertical, and thus gets cut off and there's a big black section on the side.
On my iPad, though- everything works fine! The application rotates as expected and resizes itself.
What am I doing wrong here? Thank you tremendously for any help.
Why are you programmatically loading the storyboard? If there's no specific need to do that, I'd suggest just using the template app delegate code. Better yet, create a completely new, fresh project and just copy over your storyboard. It won't necessarily make sense, but... I bet it will work!

iOS 8 Orientation Issues : Keyboard ends up in incorrect position

I have a universal project for iOS that was created in xCode 5 that I am trying to port to xCode 6. Everything seems to have been fine since I am not using LaunchScreen and iPhone 6 and 6 Plus scale the application to their resolutions.
The problem occurs when device changes its orientation.
Scenario:
It only occurs on iPhone 6 and 6 Plus.
Open Login screen with username and password fields. Rotate the device to Landscape, and tap username or password field. The keyboard appears in the middle of the screen with half cut. Rotating back to portrait hides the keyboard altogether and it no longer appears on screen no matter which field you tap on.
To get the keyboard back, rotate back to Landscape, tap on a field rotate device to opposite Landscape (don't let it go in Portrait). The keyboard suddenly becomes normal and acts fine.
I got the same problem, and that's because your app is launched in scaled mode.
It seems that Apple didn't go the full blown way to handle landscape in this scaled mode.
The solution is to switch to non-scaled mode for the iPhone 6-6Plus, using the trick specified here: How to enable native resolution for apps on iPhone 6 and 6 Plus?
Note that this will likely break a lot of your screens in the process.. but there's no other solution.
I have faced this issue with scalable mode of the app. Though supporting non-scalble mode (by adding iPhone 6 & 6+ launch images to xcassets) solves this problem, it was not permissible in my case as screens had static layout for each orientation.
I could solve this problem by avoiding the incidents of changing the root view controller of the window. Instead, the new view controllers have been added (with balancing removal) as subview (and hence childViewController) to the existing root view controller.
Everything is ok on iOS6/7, But not iOS8.
The orientation of the keyboard on iOS 8 is not the same as status bar.
If your application runs only portrait mode you can stop generating orientation notifications;
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
I have faced this issue, and after some research I found some stuff, that caused such bug.
In my AppDelegate I changed window rootViewController to show different ViewControllers depends of authorization status
if (!auth)
{
self.window.rootViewController = [[AuthViewController alloc] init];
} else {
self.window.rootViewController = [[DataViewController alloc] init];
}
I removed this and move controller select logic to NavigationViewController
if (!auth)
{
self.viewControllers = #[[[AuthViewController alloc] init]];
} else {
self.viewControllers = #[[[DataViewController alloc] init]];
}
and make this NavigationViewController as Storyboard initial view controller.
Hope it helps!

Weird Bug in XCode StoryBoard after upgrading to iOS SDK 7.1

Last night I updated XCode and the iOS SDK.
It looks like it messed up the UINavbar on the storyboard, here is a pic:
It shows two titles overlapping, if I delete the title , then there is still another one in the background, Im not able to remove that second one.
The strange part is it magically disapear, if I run the app.
XCODE version --> Version 5.1 (5B130a)
iOS SDK---------> Version 7.1
Yes, there's a new property for the uiviewcontrollers named "exteded edges" you must uncheck this in the interface builder inside the uiviewcontroller preferences. Or by inserting this code in your view did load. This will tell the controller not to draw the view under the navigation bar.
if ([self respondsToSelector:#selector(edgesForExtendedLayout)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}
I checked again and there was an extra navigation bar, its weird that It shows only after I upgraded, I think something happen with that view because I embedded it into a navigation controller.

Hiding the Status Bar for an iPhone app running on iPad

My iPhone app requires that the status bar be hidden at all times. This is generally easy to do, and it works if I only run the app on an iPhone. However, if I run the app on an iPad, the status bar still appears at the top of the content. So, how do I make sure the status bar is hidden no matter device my iPhone-only app is running on? I'm currently doing the following in my code:
Calling this method for each view controller(I actually created a category on UIViewController that implements this automatically for any VC, but it's basically the same as writing it in each vc file):
-(BOOL)prefersStatusBarHidden{
return YES;
}
I also set "status bar is initially hidden" to YES and "View controller-based status bar appearance" to NO in Info.plist. I've also tried detecting which device is being used and calling
[UIApplication sharedApplication]setSetStatusBarHidden:YES]
in the AppDelegate, but no luck there either. So, I believe I've tried just about everything that one would think to try.
It seems this was introduced into iOS 7.1 and affects non-retina iPads running iPhone applications with retina graphics.
No solution for developers. I think Apple will have to patch this one...
Problem devices:
iPad 2
iPad Mini (non-retina).
Problem does not exist in iOS 7.0 and status bar issues can be fixed for 7.0 with the other solutions posted.
Update for September 2014 - iOS 8:
This bug is fixed for iOS 8!!!!!
Add this code.
- (BOOL)prefersStatusBarHidden{
return YES;}
Add an property in YourViewController as
#property BOOL statusBarHidden;
and then in ViewDidLoad add the following lines of code
[self prefersStatusBarHidden];
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
self.statusBarHidden = YES;
Then add an method in YourViewController
- (BOOL)prefersStatusBarHidden{
return YES;}
and also don't forgot to add the #import <UIKit/UIKit.h> in your code it works great for IOS6.1 & 7.0 :)

Resources