Sometimes you have a UIViewController class that for some reason or another, doesn’t have a xib file attached.Nib file, nib file, xib and Xib files are all the same files. In the new Xcode 4 and further, the old nib is now xib extension.
The reason to create an attachment to the Xib file is simple – you want to have events from controls on the GUI friendly Xib file sent to your UIVIewController object.
To add a new Xib file, select new file on Xcode and then go to user interface and select View.
Next, you select the family of that nib and the name, and you got a new nib.
This nib however is not connected to anything, so lets create the connection.
If you don’t already have a UIViewController class that is nib-less, create one.
Attaching the new nib to the class is very simple:
- Click the nib file, you will get the designer, click on the white empty view.
- Click on the File’s owner (the empty cube at the top)
- Next, go to identity inspector and from the classes select your nib class.
- Ctrl+Drag from the file owner box to the view (the empty white square beneath the brown square with the number “1” on it) and click on the “view” in the black menu.
That’s it! you are all done. now you can add components to this view and use them from the class by dragging them.
If you are using this UIViewController dynamically, use the initWithNibName initializer, and put your nib file name.