why does this application delegate code work

126 views Asked by At

Just starting up with iPhone development.

I'm not sure why this code works. I've created a new UI controller, then added it's details to the application delegate *.h file and the *.m file, also then connected things up in IB. Things work when I run it, so that I do actually see my new view from the controller I added...

However I see in the didFinishLaunchingWithOptions method in the application delegate I never actually created my controller? (i.e. alloc'ed it / created the object).

How come things actually work?

(A) *.m

#import "windowsBasedAppDelegate.h"
#import "gregsController.h"

@implementation windowsBasedAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [self.window addSubview:viewController.view];

    [self.window makeKeyAndVisible];

    return YES;
}

(B) *.h

#import <UIKit/UIKit.h>
@class gregsController;

@interface windowsBasedAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    gregsController *viewController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet gregsController *viewController;

@end

thanks

1

There are 1 answers

0
Carl Veazey On BEST ANSWER

If you created an object in interface builder, and connected the outlet, then the nib file actually instantiates the object for you, using initWithCoder: