views:

81

answers:

2

I am simulating an "iPhone-only" app in iPad. The binary simulates fine in the iPhone simulator, but when attempting to simulate in the iPad, the initial background image appears, but then the screen just goes black. (Xcode v4.1, SDK 4.1)

The app has only one view, which is controlled by a single custom UIViewController. (SoloViewController) The only view managed by SoloViewController is contained in a "detached" nib called "mainview.xib".

I initialize the SoloViewController in my AppDelegate like so:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    SoloViewController *vc = [[SoloViewController alloc] initWithNibName:@"mainview" bundle:[NSBundle mainBundle]];
    self.soloViewController=vc;
    [vc release];

    [window addSubview:[soloViewController view]]; 
    [window makeKeyAndVisible]; 
}

My Info.plist file has the "Main nib file base name" set to "MainWindow", which I believe is the default Xcode gives you when you first create a ViewController-based project. Anyway, I just left that as-is. However, when attempting to simulate in iPad, the log says:

Failed to load NSMainNibFile MainWindow.

iPhone simulator and hardware have no problem with this...

If I set the "Main nib file base name" key to "mainview" to use the xib file for the view, I get this error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x7a01270> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'

I've double-checked the xib in IB and all of the outlets are properly defined and connected to SoloViewController.h & SoloViewController.m. What am I doing wrong here!?

Also - if I leave the NSMainNibFile blank, then the iPhone simulator just comes up with a black screen. (no errors in log)

A: 

Similar behavior can happen when you reference constants in your code (or via IB code-generation) that are defined in iOS 4x or later, while the iPad runs 3.2x, and knows nothing of these key definitions.

Make sure your target has the iOS Deployment Target set to iOS 3.2 and the Base SDK to 4.1. If you changed these values, do a clean before recompiling. Unfortunately, I don't think you'll see a compiler warning in this case.

Hope that helps.

TyB
Hmm. Nice thought, but same result. iOS Deployment Target set to: iOS 3.2, Base SDK to 4.1 Device (or Simulator, w/ same result).
Sly
A: 

As it turns out the project, in this case requires a MainWindow.xib file. In my case, I had inadvertently removed this file from the original project template and thought it was ok, since it simulated and ran fine in hardware. (iPhone) The MainWindow.xib file requires a File's Owner of type "UIApplication", First Responder of type "UIResponder", an App Delegate of a custom type pointing to your application delegate. (name will vary depending on what you've named your project) Lastly there is a Window of type UIWindow. All of these are default settings, with exception of the App Delegate.

Once I included a xib configured this way, the app loads as expected in both iPhone & iPad simulators. (Still not clear as to why the iPad simulator treats the absence of the MainWindow.xib file differently)

Sly