CocoaDev

Edit AllPages

I’ve found this code from Apple’s DragAndDropOutlineView example:

(newbie question at bottom) :-)

#import <Cocoa/Cocoa.h>

@interface ImageAndTextCell : NSTextFieldCell { @private NSImage *image; }

@end

and:

@implementation ImageAndTextCell

@end

My question is this: how exactly do I implement this? Right now, I’ve got another class that has only a few attributes and accessor methods. But I can’t figure out how the code above would work with my custom class (I’m assuming I might make an instance of the above in my class?).

If anyone could enlighten me that would be swell…

I’m going to answer my own question… But, feel free to critique what I’ve got here; I’m sure there must be a better way.

Anyways, all you really need to do, is implement these 2 sets of code:

// add this to your - (void) awakFromNib method NSTableColumn *col = [self tableColumnWithIdentifier:@”whatever”]; [col setDataCell:[[[ImageAndTextCell alloc] init] autorelease]];

id cell; // implement this in your datasource cell = [aTableColumn dataCell]; [cell setImage:[NSImage imageNamed:@”OAHelpIcon.tiff”]];

But, make sure you import the previous code too…


ok it’s work fine but ….

lose the setting font for cell text

ideas ?

I was recently playing around on my own with this, and the way I did it was slightly different. I similarly made the ImageAndTextCell subclass, but instead of having my own setImage, I made an ImageAndTextInfo class (as a subclass of NSObject), which encapsulates an image and a title. That way, i can just return an ImageAndTextInfo instance in my data source -tableView:objectValueForTableColumn:row: like normal and have my cell access it by self objectValue] image] or [[self objectValue] title]. I also overrode the [[NSCells -image and -title accessors to return those values. It simplifies things a bit in my opinion.

– BrianMoore


Have a little example ? TKS !

– Toni Moore