1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Resolved NSImage in NSTableView column

Discussion in 'Mac Programming' started by larswik, Dec 2, 2011.

  1. larswik, Dec 2, 2011
    Last edited: Dec 3, 2011

    macrumors 65816

    #1
    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];
        
    }
    
     
  2. macrumors 65816

    #2
    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?
     
  3. Moderator emeritus

    kainjow

    #3
    Here you go.
     

Share This Page