Graphics Programs Reference
In-Depth Information
return headerView;
}
You don't have to specify the suffix of the file name; NSBundle will figure it out. Also,
notice that you passed self as the owner of the XIB file. This places the instance of
ItemsViewController in the File's Owner hole of the XIB file.
The first time the headerView message is sent to the ItemsViewController , it
will load HeaderView.xib and keep a pointer to the view object in the instance vari-
able headerView . The buttons in this view will send messages to the Item-
sViewController when tapped.
Now that you've created headerView , you need to make it the header view of the table.
This requires implementing two methods from the UITableViewDelegate protocol
in ItemsViewController.m .
- (UIView *)tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)sec
{
return [self headerView];
}
- (CGFloat)tableView:(UITableView *)tv heightForHeaderInSection:(NSInteger)sec
{
// The height of the header view should be determined from the height of the
// view in the XIB file
return [[self headerView] bounds].size.height;
}
These two methods are listed as optional in the protocol, but if you want a header view,
you must implement both.
Now that these methods are implemented, the UITableView will send these messages
to its delegate , the ItemsViewController , when it needs to show the header
view. The first time tableView:heightForHeaderInSection: is sent to Item-
sViewController , it will send itself the message headerView . At this time,
headerView will be nil , which will cause headerView to be loaded from the XIB
file.
Build and run the application to see the interface. Ignore the incomplete implementation
warnings; you'll implement toggleEditingMode: and addNewItem: shortly. Until
you do, tapping a button will generate an exception because the action methods of the but-
tons are not implemented.
Search WWH ::




Custom Search