Unable to load UIView with initWithNibName in Apple SDK 3.1.3

Posted by James Foster on Stack Overflow See other posts from Stack Overflow or by James Foster
Published on 2010-03-28T19:51:06Z Indexed on 2010/03/28 19:53 UTC
Read the original article Hit count: 1061

I am trying to load my UIViewController and corresponding UIView programmatically in the AppDelegate class. I have the following in the applicationDidFinishLaunchingMethod of the AppDelegate class:

  • (void)applicationDidFinishLaunching:(UIApplication *)application {
    NSLog(@"--- AppDelegate applicationDidFinishLaunching Start");

    // Override point for customization after application launch //MainController *controller = [[MainController alloc] initWithNibName:@"MainView" bundle:nil]; MainController2 *controller = [[MainController2 alloc] initWithNibName:@"MainView2" bundle:nil];

    if (controller.view == nil) { NSLog(@"--- controller view is nil!!!!!!"); } [window addSubview:controller.view]; [window makeKeyAndVisible];

    NSLog(@"--- AppDelegate applicationDidFinishLaunching End"); }

Basically the view in the viewController doesn't load and when the application launches, it just shows the blank window. What is funny is that it worked before and then just stopped working. I am wondering if this is a bug in iPhone SDK 3.1.3??? This is a really annoying issue, and I was quite a ways along in a new project when I started having this problem and had to start over with a blank project and copy over all of my resources, when it started happening again... I have uninstalled iPhone OS 3.1.3 and reinstalled and the problem prevails...

I also created a second UIViewController class and corresponding nib which DOES LOAD just fine... I am not sure why one works and the other doesn't it...

You can download a sample project which demonstrates this issue at the following link:

http://www.mediafire.com/?nmhnmhbeyki

To switch back and forth between the working/nonworking UIViewController and UIView simply comment comment/comment out the initWithNibLine lines in the AppDelegate and the corresponding #import "MainController.h" statements in the appdelegate.h file...

Any ideas???

The sample project I have linked to isolates the problem in as few files/lines of code as possible... I appreciate any help you might be able to provide.

Thanks, James

© Stack Overflow or respective owner

Related posts about iphone

Related posts about SDK