What is [indexPath row] doing exactly?


#1

In this piece of code

[code]- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“UITableViewCell”];

if (!cell) {
    
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}

BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];

[[cell textLabel] setText:[p description]];

return cell;

}[/code]

I’m unclear on how all five items in the store are returned to the variable based on the [indexPath row] argument. I was under the impression that the row property of an IndexPath object returned a single integer that corresponds to the row. So if you have something like this:

Section 1

row 1
row 2
row 3

Set up an NSIndexPath object like this:

NSIndexPath *object = [NSIndexPath IndexPathForRow: 3 InSection:1]

Then find the row like this, which should contain an int value of 3:

int row = [object row]

In the code above, what exactly is going on in objectAtIndex: [IndexPath row] that makes it able to return all five objects to the variable and print their descriptions? Why doesn’t [indexPath row] correspond to a single object in the array since the row property normally returns a single integer value?


#2

Log the index path’s row to the console in this method somewhere with NSLog(@"%d", [indexPath row]);

Note that the method gets called five separate times, not that it somehow returns 5 things.