Mac NSImage in NSTableView column

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I have an NSTableView with about 6 columns. All the columns are text but the first one I want as an NSImage. Reading through the docs it seems that a cell can be text or image initWithText or initWithImage. So in a delegate method for the tableview I had it look at the identifier and if it was the image it would make an image Cell and return that instead of the default which seems to be the text Cell. The end result is a blank column?
Code:
-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    Item *newItem = [tableViewItemList objectAtIndex:row];
    NSString *identifier = [tableColumn identifier];

    if ([identifier isEqualToString:@"image"]) {
        NSCell *imageCell = [[NSCell alloc] initImageCell:newItem.image];
        return imageCell;
    }
    else
        return [newItem valueForKey:identifier];
    
}
 
Last edited:

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I got it working. I dragged in an Image Cell and dropped in on my first column and now the images load just fine.

Could someone tell me how to mark this thread solved, I can't seem to find it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.