iPad crashes when running iPhone app in compatibility mode - iphone

I just had one of my apps reviewed, and I never knew this but apparently an iPhone specific app must also be able to run on the iPad in compatibility mode... I never knew this, and it doesn't really make sense.
Anyways, my app is crashing when calling didFinishLaunchingWithOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *rootViewController;
rootViewController = [[[WPViewController alloc] initWithNibName:#"WPViewController_iPhone" bundle:nil] autorelease];
self.viewController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
self.viewController.navigationBar.barStyle = UIBarStyleBlack;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Using NSLog, I can see that it crashes when I call [self.window makeKeyAndVisible]; And also, if I remove that line of code and run it in the iPad simulator, it does not crash, but obviously shows a blank screen. The app runs fine on the iPhone simulator
Any ideas? or places to start looking?

Related

GUI not proper after duplicated xib for ipad?

I have duplicated iphone xib into iPad xib by duplicating the target, now my most of the xibs are converted properly into iPad size, however some xibs still showing as iphone size only. Apart from that most of the GUI functionalities like Alert View showing, Action sheet are all not as per iPad. What changes do I need to make to work perfectly for iPad.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Edit: GUI ISSUE I have given two option in that Action sheet YES and NO, only YES showing NO is hiding somewhere..
thanks
Problem is not with conversion, Its with the usage of Action sheet in ipad. Check how to use Action sheet in ipad,
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
it may fix your problem
You aren't loading the correct NIB when the app starts. This is the code provided by the Xcode "Single View" App Template, which detects the device and loads the appropriate NIB file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[MainViewController alloc] initWithNibName:#"MainViewController_iPhone" bundle:nil];
} else {
self.viewController = [[MainViewController alloc] initWithNibName:#"MainViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

need help understanding my error on my first iPhone app [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
applications expected to have a root view controller console
I'm trying to build the first app by following a book step by step but I guess I'm making a mistake.
it's a simple view app with just a logo nd a label and then I click build and run and it says "build succeded", but when ios simulator pop up the app is still blank, even if I go back home and ropen the app nothing change.
I see on the debug window this statement:
2012-10-26 04:07:03.376 welcome[1219:c07] Application windows are expected to have a root view controller at the end of application launch
AS far as I understand my app lacks of a root view controller but how can I implement it?
You specify the root view controller in your appDelegate class. It should look something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
The important lines that you need to add are:
self.viewController = [[[ViewController alloc] initWithNibName:#"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
And under initWithNibName you put the name of the xib you created your interface in.
Note: Only add autorelease if your project isn't using ARC.

White screen for ios Project

I just tried to duplicate an existing iOS project. After copying over all the files, and fixing all the errors, I am simply getting a white screen when the app launches. Any ideas? I do not have any MainWindow.xib files, nor are any xib files mentioned in my plist. Here is my launch code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenu];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
When i set a breakpoint in MainMenuViewController's viewDidLoad method, it hits it just fine. Any ideas?
I just figured it out... all of my .xib files were missing from the "Copy Bundle Resources" section of Build Phases.
MainMenuViewController *mainMenu = [[MainMenuViewController alloc] init];
Had you set view's frame of mainMenu?

iphone app not working ipad simulator

My iphone app runs on iphone simulator and devices but not on ipad simulator. It doesnt showing any errors but the application is not launching just blank black screen only displays.
While running in ipad simulator 5 it showing following error "applications are expected to have a root view controller at the end of application launch"
My application didFinishLaunchingWithOptions code is as below :
rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
[self.rootViewController.view setFrame:CGRectMake(0, 20, 320, 460)];
[self.window addSubview:self.rootViewController.view];
[self.window makeKeyAndVisible];
return YES;
And my main.m code is as below :
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
What is the wrong with this???
Go on the App Target info and set "Target device Family":"iPhone" then it works fine both on iphone and ipad simulator and device both.
What if you change this:
rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
to this:
self.rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
Check....Navigation Controller delegate must have been connected (delegate > AppDelegate) in IB.

Converting an iPhone app to Universal in Xcode 4

I could use a little clarity here.
I've opened a project that is a completed iPhone app. Then selected the target, selected "Universal" from the Summary/Devices dropdown, and followed the prompt to "Make a Universal App."
Xcode created a folder "iPad" with the file "MainWindow-iPad.xib" within.
Fine.
Now I duplicated all of my other nib files, and added "-iPad" after their name. I.e. "MySpecialVC.xib" was duped and renamed "MySpecialVC-iPad.xib." The thought was that Xcode knows some zoodoo about finding the correct xib for the device.
Not so fine.
Then I read that the "-iPad" had to be "~ipad" (tilde, then lower-case ipad). This solved the problem with some of the xibs, but not all of them.
Dang if I can't figure this out. Is there a RIGHT way to do this?
When I create a new universal project, I get this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
So it's clear the code is explicitly choosing a xib file. Is this not the case for your project?