views:

235

answers:

5

I have just noticed that my ViewController does not call init (See below) when it starts up.

-(id)init {
    self = [super init];
    if(self) {
        NSLog(@"_init: %@", [self class]);
        otherStuff...
    }
    return self;
}

Is there a reason for this, or is it replaced by viewDidLoad

-(void)viewDidLoad {
    otherStuff ..
    [super viewDidLoad];
}

cheers gary

A: 

I think you need to use initWithNibName:bundle: Docs

Abizern
+1  A: 

awakeFromNib is commonly used.

Elise van Looij
+1  A: 
  • (void) init works fine if you create the object in code, but you DO have to make sure it's the one you call. It doesn't do any good to flesh out the templated initWithNibName:bundle: method and then call the other one.
Amagrammer
+1  A: 

To better understand designated initializers for a UIViewController read this blog post by Aaron Hillegass. It set me straight!

Meltemi
+1  A: 

It's not replaced by viewDidLoad. It's just that init's not called by initWithNibName:bundle:.

I just write my setup code in viewDidLoad.

Frank Shearar