How is an AppDelegate instanciated?

Posted by pwny on Stack Overflow See other posts from Stack Overflow or by pwny
Published on 2011-06-22T07:27:33Z Indexed on 2011/06/22 8:22 UTC
Read the original article Hit count: 209

Filed under:
|
|

I have an iOS application for which I want to create a ViewController programmatically.

I started an empty XCode project and modified the main method so it looks like this

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"MyAppDelegate_iPad");
    [pool release];
    return retVal;
}

The app is a Universal Application, MyAppDelegate_iPad is a subclass of MyAppDelegate, which is a subclass of NSObject <UIApplicationDelegate>.

My problem is that the applicationDidFinishLoading method I've overridden in MyAppDelegate_iPad is never called (break point on the first line never hits). The method looks like this

-(void) applicationDidFinishLaunching:(UIApplication *)application {
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    if(!window)
    {
        [self release];
        return;
    }
    window.backgroundColor = [UIColor whiteColor];

    rootController = [[MyViewController alloc] init];

    [window addSubview:rootController.view];
    [window makeKeyAndVisible];
    [window layoutSubviews];
}

I removed the line to link to a nib file from my plist file (I used to get the default "My Universal app on iPad" white screen) and now all that is displayed is a black screen. applicationDidFinishLoading is still not being called.

Am I doing something wrong? How should I properly create my AppDelegate instance?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios