Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hervey

macrumors newbie
Original poster
Sep 23, 2009
19
0
The init method is NOT called on the second snippet of code, but is called on the first snippet. I don't understand.

Code:
@implementation testAERAppDelegate
@synthesize window;

-(id)init {
	[super init];
	NSLog(@"init"); ...
return self;
}

Code:
@implementation RootViewController
@synthesize pickerView,dateFormatter;

-(id)initWithCoder {
	[super init];
	NSLog(@"init");
	return self;
}
 
My Bad! I copied over other code I was trying out. The correct posting of the code that's NOT working is:

Code:
@implementation RootViewController
@synthesize pickerView,dateFormatter;

-(id)init {
	[super init];
	NSLog(@"init");
	return self;
}

Sorry for the confusion. Thanks for your help.
 
How are you instantiating this class? Can you post the code where you are using the class?

Is this RootViewController from inside a XIB/NIB? If so, it technically doesn't get init'ed when the app is started, but rather gets unarchived from the XIB. When this happens, the awakeFromNib method is called.

Basically the rule of thumb, is if the class is being instantiated from code, init is called, but if the class is being instantiated from Interface Builder, then you want awakeFromNib.
 
One from xib, one from code. Thank you for helping clarify this basic element, and the clear manner you made it clear for me. I have been studying Cocoa since March, and this basic element had escaped me.

Cheers.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.