views:

409

answers:

2

I've choosen the "view-based" application template in Xcode. The myProjectViewController.m has the following code:

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

That sounds good. But: The template generated a myProjectViewController.xib file. What I dont get is: How does Xcode connect the ViewController with that nib? Where's the part in the template code that says: "Hey, load that myProjectViewController.xib now!"? I mean... can I just delete that not-wanted nib file without setting anything else up appropriately?

A: 

yep you can just delete the nib and implement that method IB connects using the name of the class in the NIb, in IB you actually set a view as the file owner of the view. so when you call initwithnib:"nibfilename" it knows what you are talking about.

The elements are wired up using IBOutlets and IBActions

Bluephlame
I removed the xib. Now it crashes when I launch. Is there something that I _have_ to implement in -(void)loadView?
Thanks
how do you create the view and load it? you need to pass nil into the initwithnib: constructor.
Bluephlame
I don't know how the myProjectViewController is ignited. It's just there and is used. I don't see any starting point. The App Delegate adds the view of that view controller as a subview to the window. The App Delegate also uses a nib. There, it seems like if it would create an instance of the myProjectViewController, because in the App Delegate there is an outlet for this.
Thanks
it's in the mainWindow.xib a reference to the viewcontroller. you should be able to delete the nib name in the view controller attributes in IB. look around will teach you something new about how nibs work. I just learnt something
Bluephlame
+1  A: 

You may wish to refer to my answer to this question, where I describe the specific files that need to be altered to do completely programmatic generation of your view hierarchy. Also, some of the references linked to in the answers to this question may be of use to you.

Brad Larson