ios 6 iPhone window.rootViewController crashes - ios

My app works fine with iOS 5.1 on both iPad and iPhone. In iOS 6 app works fine on iPad but crashes in iPhone while setting the window.rootViewController = navigationViewController. I have set Exception break point which stops execution at this piece of code in application didFinishLaunchingWithOptions. I even tried adding it as [window addSubView:navigationViewController.view] but no luck. Has any one faced similar issue.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
rootViewController = [[SpringboardViewController alloc] initWithNibName:#"SpringboardViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = nav;
self.window makeKeyAndVisible];
return YES;
}

could you write an exception ?
take a look at these questions
applications expected to have a root view controller console
Applications are expected to have a root view controller at the end of application launch

Thanks for your replies guys i figured out the problem ,problem was with the application supportedInterfaceOrientationsForWindow where i was returning UIInterfaceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait since app debugger was struck at self.window.rootViewController = nav, i thought problem was with this statement.
Thanks Ravindharan and Ogres.

Related

Xcode App won't load view sometimes

my project runs without storyboards, so im loading my view inside AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.window.rootViewController = [[SYLoginController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
It used to work on iPhone 6 sim 9.3 but now, on all simulators it only shows a black screen. But on my iPhone 6 Device it works. Whereas on another iPhone 6 it also shows a black screen. Those two iPhones are literally the same 16gb iPhone 6 bought at nearly the same time.
In SYLoginControllers viewDiDLoad I'm logging the text of one of the buttons. Only on my device it prints the text, on all simulators and the other iPhone it prints (null), so i assume that the xib is not properly loaded.
SYLoginController is a UIViewController, and the related xib holds a UIView with its FilesOwner set to SYLoginController. I really can't see why it only works on this particular device. Also i tried [[SYTabBarController alloc] initWithNibName:#"SYLoginController" bundle:nil], this also does not work...
Did you tried to wrap it arround a Navigation Controller?
SYLoginController *syVC = [[SYLoginController alloc]initWithNibName:#"SYLoginController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] syVC];
self.window.rootViewController = nav;
Also check again if Custom Class is set to SYLoginController in the XIB-File. And the View is connected to the Files Owner.

iOS 8 Landscape mode not work properly an Not Rotating app

i am developing app using ios8 support with portrait and Landscape mode both,
but problem is that when i try to rotate my Device to Landscape mode it cant work for me.
i test same thing in my other device iPhone 4 with ios7.1.2 it work fine but not working with ios 8.1 in iphone 4s
please give me suggestion if any one also have the same problem.
ARViewController* metaioCloudPlugin = [[ARViewController alloc] initWithNibName:#"ARViewController" bundle:nil];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = metaioCloudPlugin;
[self.window makeKeyAndVisible];
====
This is my AppDelegate code for main window root view.
Thanks in advance.
i fixed this issue .
Remove below line from code and its work fine now.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
refer this link
iOS 8 - App not rotating appropriately
I was facing the same issue, while I was updating the xib base project for iOS8,
I found the solution inside your question,
thanks for asking :)
self.window.rootViewController = loginScreen;
While navigating to the screen
loginScreen = [[LoginScreen alloc] initWithNibName:#"LoginScreen" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginScreen];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = loginScreen;
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

How to properly use a UINavigationController

I just recently started programming for iOS/iPhone. I thought I knew what I was doing until XCode5/iOS7 came around. Previously, I created a class derived from UIViewController with a XIB, added a label, and programatically added it to the rootWindow:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
... // boilerplate code
MyViewController* myRoot = [[MyViewController alloc]init];
self.window.rootViewController = myRoot;
To use a navigation bar, I changed the code slightly:
MyViewController* myRoot = [[MyViewController alloc]init];
UINavigationController* navigationController = [[UINavigationController alloc]init];
[navigationController pushViewController:myRoot animated:YES];
self.window.rootViewController = navigationController;
This seemed to work fine. However, on iOS 7 the controls at the top of my custom view controller appear to be behind the navigation bar. Some googling resulted in this link which describes changes in the status bar.
It also seems to indicate that,
A) UINavigationController should handle the changes automatically
B) "auto layout" should handle the changes automatically,
and that I shouldn't need to worry. However, my sample app above doesn't appear to handle anything automatically.
I also found some other sample code which uses the controller differently: adding the navigation controller's view as a subView to an existing view. This sort of makes sense for adding a navigation controller later on in an app's lifetime, but I am trying to set one up on launch.
Am I using the UINavigationController correctly?
What do I need to consider for iOS7 vs. earlier versions?
How do I configure "Auto Layout" (I don't see this in interface builder anywhere)?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}

xcode backward compatibility methods

I've a project that runs perfectly (I hope :)) on ios 6 SDK.
When I try to test it on ios 5 simulator, I've a blank view so I suppose that I've used some uncompatible methods.
How Can I discover and verify which methods doesn't works?
Or are there some problems with my xib?
EDIT:
My appDelegate code:
LoginViewController *loginViewController =
[[LoginViewController alloc] initWithNibName:"LoginViewController.xib" bundle:[NSBundle mainBundle]];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
navigationController.navigationBar.hidden = YES;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
if (![self connect]){}
[self.window makeKeyAndVisible];
"Apple and backward compatibility" is an oxymoron. It is not interesting to Apple if you publish apps that use older than the current iOS version, you know how hard they force developers and consumers to move on. I wouldn't bother and I would set the bottom line at 6.

UIWindow's root view controller does not rotate to landscape at app launch

I am developing a xib-based landscape-only app. The app launches in landscape correctly. However, the view in my main ViewController is presented in portrait. That is, it is rotated 90 degrees so that the image appears cropped and does not take up the entire screen. If I use my interface to present a modal view controller then return to the main ViewController, the issue corrects itself (the view is presented in landscape). This problem did not occur under Xcode 4.2. It occurred after upgrading to Xcode 4.3, and the only code changes that were made were automatically implemented by Xcode when I upgraded the project settings.
Based on advice in other posts, I verified my Info.plist settings for Supported Interface Orientations and Initial Interface Orientation. I overrode the shouldAutorotateToInterfaceOrientation method for each of my view controllers to return YES only for landscape orientations. Also, I turned off auto resizing for the view, as I never want the size/orientation of the view to change.
Based on the ideas in this link [1], I suspected the problem is that the view is not receiving the call to change orientation at launch, possibly due to the removal of the MainWindow.xib concept, which appears to be replaced by the following Xcode-inserted code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I modified this method to generate a generic root view controller from which my ViewController class is presented, as shown in the code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController* myViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.viewController = [[UIViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.viewController presentModalViewController:myViewController animated:NO];
return YES;
}
Voila! This solved my problem. However, to me it feels like a change at a fundamental level, which I don't want to make at this point in my development. What I intended to be my root view controller is now a modal view. Does anyone have another solution to this issue?
Thanks in advance!
I had this same issue: an app which was meant to be in Landscape that assumed the ViewController was always in Portrait. I made tons of changes to every aspect of the project and info.plist, including giving the main UIWindow a root-view controller which was landscape. It still didn't work. I eventually undid all the changes and just added the two lines noted below to my app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[_window addSubview:[_viewController view]];
glView = _viewController.glView;
// THIS FIXED ORIENTATION FOR ME IN IOS 6
_window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// END
...my other setup code here...
}
Nothing else was necessary.
It appears that, for some reason, in iOS 6 the UIWindow root-view-controller setting is sometimes ignored in Interface Builder. I am sure my reasoning is wrong somewhere, but I thought this might well help prod someone in the direction of a fuller, more exhaustive answer.
In iOS 8, settings windows frame to the UIScreen is also necessary, as it won't get automatically updated.
self.window.frame = [UIScreen mainScreen].bounds;

Resources