views:

443

answers:

1

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

+1  A: 

MainController is overriding "loadView", but its "loadView" implementation does not actually load anything (or call [super loadview]). Hence, no view.

David Gelhar
Found the issue... Basically DO NOT uncomment the loadView method unless you are constructing the views and adding them manually (w/o a nib), otherwise you are overriding the default behavior which takes place in initWithNibName... lesson learned after 4 hours of head-scratching...
James Foster
Uncommenting the loadView method isn't a problem as long as you call loadView on the superclass
pheelicks