views:

426

answers:

3

Hi

I just have a basic (noob) question about cellForRowAtIndexPath get called?

I'm working through example code and I don't see it explicitly called anywhere?

Does any component of type UITableViewComponent automatically call this function when it is created?

Thanks

A: 

This is called for each cell when the corresponding UITableView gets drawn. An index path is passed in, and based on the section and cell numbers, your code should generate a UITableViewCell to be displayed in the UI.

You can look here for a quick tutorial into how UITableViews work.

Aaron
+2  A: 

When a UITableView is displaying this method gets called per row. In it you will customize each cell with particular data for display.

Here's the class reference.

Here's a sample:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"FriendCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    NSUInteger row = [indexPath row];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    Item *i = [itemArray objectAtIndex:row];
    cell.textLabel.text = [i name];
    cell.detailTextLabel.text = [i brewery];
    [i release];
    return cell;
}
sw
A: 

That very helpful, thanks guys.

Learning new languages is fun but can be hairy starting out!

dubbeat