Skip navigation.
 
mlRe: NSTableView, adding a NSImage in the cell
FROM : Andrew Yager
DATE : Fri Jan 03 19:50:01 2003

Hi,

You want to use an NSImageCell I believe... Basically... In your
awakeFromNib you want to get the right table column, and set it's data cell
to be an NSImageCell, (sort of like this)

NSTableColumn* theColumn =
        [mTableView tableColumnWithIdentifier:@"SubScript"];
[theColumn setDataCell:[[NSImageCell alloc] initImageCell:nil]];


You cold do this in two places - if you are using a custom NSTableView then
you can stick this in it's awakeFromNib, or alternatively, you can do it in
the window controller's awakeFromNib (which is where I did it in this bit of
code... I've actually done both)

Then, in your

- (id)tableView: objectValueForTableColumn: row:

Delegate method, you want to return the image for the right column...

Eg

- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
    NSString* ident = [tableColumn identifier];
    if ([ident isEqual:@"SubScript"])
    {
        return [[[self script] itemAtIndex:row] image];
    }
    // else if... Etc...
}

Hope this helps ;-)

Andrew

On 4/1/03 1:59 PM, "Ben Mackin" <<email_removed>> wrote:

>
> What I want to do is similar to mail, add a dot next to unread items and no
> dot next to read items. I know how to do everything except for the part of
> drawing the NSImage into my NSTableView. Since everything I have been
> dealing with so far was based around NSStrings, it has been easy. My code
> works. If I check the items in the tableView, read items return YES and
> unread items return NO. So it is just a matter of drawing the NSImage to the
> correct place.
>
> I hope something in that made some amount of sense :)
>
> In my browser.m file I have:
>
> - (void)setHasBeenRead:(bool)hasBeenRead
> {
>  NSImage *myImage;

>  if(hasBeenRead==YES)
>  {
>      fileHasBeenRead = YES;
>     
>      myImage = [NSImage imageNamed:@"read.tiff"];
>      //draw the nsimage code here
>     
>  }
>  else
>  {
>      fileHasBeenRead = NO;
>
>      myImage = [NSImage imageNamed:@"unread.tiff"];
>      //draw the nsimage code here
>     
>  }
> }
>
> My problem is I don't know where to draw the image to. Any insight would be
> very helpful.
>
> Thanks,
> Ben
>
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>


___________________
Andrew Yager
Real World Technology Solutions
Real People, Real SolUtions (tm)
ph: (02) 9945 2567 fax: (02) 9945 2566
mob: 0405 15 2568
http://www.rwts.com.au/
_________________________


Related mailsAuthorDate
mlNSTableView, adding a NSImage in the cell Ben Mackin Jan 3, 19:00
mlRe: NSTableView, adding a NSImage in the cell Andrew Yager Jan 3, 19:50