Take the 2-minute tour ×

I make all my controllers in code and most of the GUI too. Some GUI's I make with IB. I then set the file's owner to the viewcontroller and drag an connection from the file's owner to the view. But initWithNibName confuses me...

I am override the designated initializer to this

- (id)init {
    [super initWithNibName:nil bundle:nil];

    return self;

    return [self init];

Why do I not need to set which nib the viewController shall use in the init-initalizer? Because it works without. I thought I must use [super initWithNibName:@"SomeNib" bundle:nil];

In the init-initalizer

share|improve this question
So, what's the question? I think you need to reorganize your information. –  Evan Mulawski Feb 2 '11 at 19:29
Obviously not since two people already understood my question and answered it beautifully. –  LuckyLuke Feb 2 '11 at 19:31

2 Answers 2

up vote 2 down vote accepted

It works without only if your nib name is the same as your controller class name. In that case Apple does some magic. It is generally good form to specify the nib name.

share|improve this answer
Ah, is it because of that...then it make sense. I did not understand where the magic came from. –  LuckyLuke Feb 2 '11 at 19:30

From docs: If you specify nil for the nibName parameter, you must either override the loadView method and create your views there or you must provide a nib file in your bundle whose name (without the .nib extension) matches the name of your view controller class. (In this latter case, the class name becomes the name stored in the nibName property.) If you do none of these, the view controller will be unable to load its view.

share|improve this answer

Your Answer


