Graphics Programs Reference
In-Depth Information
In
ItemsViewController.m
, modify
init
to set the
navigationItem
's
title
to read
Homepwner
.
- (id)init
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
UINavigationItem *n = [self navigationItem];
[n setTitle:@"Homepwner"];
}
return self;
}
Build and run the application. Notice the string
Homepwner
on the navigation bar. Create
and tap on a row and notice that the navigation bar no longer has a title. We need to give
the
DetailViewController
a title, too. It would be nice to have the
De-
tailViewController
's navigation item title be the name of the
BNRItem
it is dis-
playing. Obviously, you cannot do this in
init
because you don't yet know what its
item
will be.
Instead, the
DetailViewController
will set its title when it sets its
item
property.
In
DetailViewController.m
, implement
setItem:
, replacing the synthesized
setter method for
item
.
- (void)setItem:(BNRItem *)i
{
item = i;
[[self navigationItem] setTitle:[item itemName]];
}
Build and run the application. Create and tap a row, and you'll see that the title of the nav-
igation bar is the name of the
BNRItem
you selected.