Graphics Programs Reference
In-Depth Information
So far, your XIB files have been loaded automatically by the implementation of
to load
TimeViewController.xib
because of code written in its superclass,
UIViewController
. For
HeaderView.xib
, you're going to write the code to have
the
ItemsViewController
load this XIB file manually.
To load a XIB file manually, you use
NSBundle
. This class is the interface between an
application and the application bundle it lives in. When you want to access a file in the ap-
plication bundle, you ask
NSBundle
for it. An instance of
NSBundle
is created when
your application launches, and you can get a pointer to this instance by sending the mes-
sage
mainBundle
to
NSBundle
.
Once you have a pointer to the main bundle object, you can ask it to load a XIB file. In
ItemsViewController.m
, implement
headerView
.
- (UIView *)headerView
{
// If we haven't loaded the headerView yet...
if (!headerView) {
// Load HeaderView.xib
[[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];
}