tags:

views:

20

answers:

1

Hi,

I have an NSTableView, with two columns. Whenever I add data to the table, both columns display the same data. How do I only update a specific column?

I'm doing Mac Dev btw.

This is the code I'm using:

- (id)tableView:(NSTableView *)streamView objectValueForTableColumn:(NSTableColumn     *)messageCol row:(int)row
{
return [[stream respond] objectAtIndex:row];
}

Thanks.

A: 

Check which column you're being asked to fill in in your implementation of tableView:objectValueForTableColumn:row:. That's why it passes you the column! Quick example, since you seem to be ignoring the "check what column you're being asked to fill in" part:

- (id)tableView:(NSTableView *)tableView
       objectValueForTableColumn:(NSTableColumn *)column 
                             row:(int)row
{
    if ([[column identifier] isEqualToString:@"A"])
        return [columnArrayA objectAtIndex:row];

    if ([[column identifier] isEqualToString:@"B"])
        return [columnArrayB objectAtIndex:row];

    return nil;
}
Carl Norum
But what value should objectValueForTableColumn: have? I've tried to putting everything there but nothing seems to work!
James Eggers
@James, the easiest way is to set the table column's `identifier` in Interface Builder, and then test that string in your implementation.
Carl Norum
that doesn't work though :( both columns are still displaying the same data.
James Eggers
@James, the code you're showing doesn't check the column at all....
Carl Norum
got it sorted, thanks.
James Eggers