Graphics Programs Reference
In-Depth Information
How do you decide which cell a BNRItem corresponds to? One of the parameters sent to
tableView:cellForRowAtIndexPath: is an NSIndexPath , which has two
properties: section and row . When this message is sent to a data source, the table view
is asking, “Can I have a cell to display in section X, row Y?” Because there is only one
section in this exercise, the table view only needs to know the row. In ItemsViewCon-
troller.m , implement tableView:cellForRowAtIndexPath: so that the n th
row displays the n th entry in the allItems array.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create an instance of UITableViewCell, with default appearance
UITableViewCell *cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"];
// Set the text on the cell with the description of the item
// that is at the nth index of items, where n = row this cell
// will appear in on the tableview
BNRItem *p = [[[BNRItemStore sharedStore] allItems]
objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[p description]];
return cell;
}
Search WWH ::




Custom Search