Graphics Programs Reference
In-Depth Information
- (NSArray *)allItems
{
return allItems;
}
- (BNRItem *)createItem
{
BNRItem *p = [BNRItem randomItem];
[allItems addObject:p];
return p;
}
Implementing data source methods
In
ItemsViewController.m
, import
BNRItemStore.h
and
BNRItem.h
and up-
date the designated initializer to add 5 random items to the
BNRItemStore
.
#import "ItemsViewController.h"
#import "BNRItemStore.h"
#import "BNRItem.h"
@implementation ItemsViewController
- (id)init
{
// Call the superclass's designated initializer
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
for (int i = 0; i < 5; i++) {
[[BNRItemStore sharedStore] createItem];
}
}
return self;
}
Now that there are some items in the store, you need to teach
ItemsViewController
how to turn those items into rows that its
UITableView
can display. When a
UIT-
ableView
wants to know what to display, it sends messages from the set of messages
declared in the
UITableViewDataSource
protocol.
From the
Help
menu, choose
Documentation and API Reference
to open the iOS SDK
Figure 9.10 UITableViewDataSource protocol documentation