tags:

views:

92

answers:

2

The App Delegate has an outlet property to the view controller, and the view controller is created in the nib.

Althoug the -viewDidLoad method of the view controller gets loaded, it seems that it designated initializer receives no call:

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
    NSLog(@"iniwinib");
    if (self = [super initWithNibName:nibName bundle:nibBundle]) {
     // do stuff
    }
    return self;
}

I also tried with -init, but this also does not receive a call. No NSLog output. Is there another initializer that I must use in this case?

A: 

Are you actually calling initWithNibName to create your ViewController somewhere in the code? If not then it will never get called, this method does not get called automatically you must call it to create your viewController from your nib. But you dont need to do call this method because you have already set the ViewController in the nib..

Daniel
They way you've said this may be very confusing to the reader. It suggests that objects that are stored in NIBs should also have initWithNibName: sent to them. That's not true. Objects stored in NIBs should never be sent initWithNibName:. Only objects that *own* a NIB should have this sent.
Rob Napier
well viewController is the only object with initWithNibName intializer
Daniel
Yes, and while view controllers can own NIBs, they can also be stored inside of NIBs. When you put a UIViewController (or any of its subclasses) in a NIB, you shouldn't then send it initWithNibName:. You shouldn't send an initializer to any object that is NIB instantiated.
Rob Napier
Yes you are right, i misread the question
Daniel
+6  A: 

-initWithCoder: is the initializer in this case (because the object is being deserialized from the NIB), but the routine you actually want here is -awakeFromNib. That's what's called after all the objects in the NIB have been constructed and all the outlets have been wired.

Rob Napier