That's correct. The File's Owner for a Nib file is the entry point into that nib. Since nothing outside your nib can refer to anything but the File's Owner, only the File's Owner can refer to other top-level items in the nib. If the File's Owner doesn't refer to them, then there is no way to release those objects when the nib is no longer needed, and they will hang around in memory.
The life cycle of a nib is something like this:
- The nib is loaded and the File's Owner is associated with an object you specified.
- Memory is allocated for all the top-level objects in the nib.
- All the outlets are hooked up as specified in the nib.
- ... stuff happens ...
- The File's Owner object is sent a release message.
- The File's Owner releases all the objects hooked up to its outlets.
As you can see, any object that was allocated in the second step will still be floating around in memory if it wasn't released in the final step.
There is also an easier way to access the view instead of dealing with the nib as an array.
1) Create a custom View subclass with any outlets that you want to have access to later. --MyView
2) in the UIViewController that you want to load and handle the nib, create an IBOutlet property that will hold the loaded nib's view, for instance
in MyViewController (a UIViewController subclass)
@property (nonatomic, retain) IBOutlet UIView *myViewFromNib;
(dont forget to synthesize it and release it in your .m file)
3) open your nib (we'll call it 'myViewNib.xib') in IB, set you file's Owner to MyViewController
4) now connect your file's Owner outlet myViewFromNib to the main view in the nib.
5) Now in MyViewController, write the following line:
[[NSBundle mainBundle] loadNibNamed:@"myViewNib" owner:self options:nil];
Now as soon as you do that, calling your property "self.myViewFromNib" will give you access to the view from your nib!
Best Answer
You have a basic understanding of what is required, though you should also consider memory management (which is slightly different for iPhone versus Mac). To really understand what is going on with this method, you should read the Nib Files section of the Resources Programming Guide. It covers the actual methods used to make the connections (which can be important), and the retain counts that various objects will have when it is done. Again, these are all slightly different between Mac and iPhone. iPhone has generally improved the consistency of how nib objects are handled.
For good measure, I always recommend that people read Memory Management of Nib Objects from the Memory Management Programming Guide. It's critical reading whether you use the lower-level methods or not.