Graphics Programs Reference
In-Depth Information
value for the number of rows that the
UITableView
should display. In the table view
for
Homepwner
, there should be a row for each entry in the store (
Figure 9.11
).
Figure 9.11 Obtaining the number of rows
In
ItemsViewController.m
, implement
tableView:numberOfRowsInSection:
. This method returns the number of rows
to display as an
NSInteger
, which is just another name for
int
.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [[[BNRItemStore sharedStore] allItems] count];
}
Wondering about the section that this method refers to? Table views can be broken up into
sections, and each section has its own set of rows. For example, in the address book, all
names beginning with āDā are grouped together in a section. By default, a table view has
one section, and in this chapter, we will work with only one. Once you understand how a
table view works, it is not hard to use multiple sections. In fact, using sections is the first
challenge at the end of this chapter.
The second required method in the
UITableViewDataSource
protocol is
tableView:cellForRowAtIndexPath:
. To implement this method, we'll need to
learn about another class -
UITableViewCell
.