Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Stratoukos

macrumors member
Original poster
Jul 15, 2008
51
0
I have a NSTableView in which I want, among other things, I want to display a NSActionCell with an image.

Inside tableView: objectValueForTableColumn:row: I have
Code:
...
else if ([[tableColumn identifier] isEqualToString:@"icon"]) {
	NSActionCell *cell = [[NSActionCell alloc] init];
	[cell setImage:[NSImage imageNamed:NSImageNameRevealFreestandingTemplate]];
	return cell;
} 
...
When I run this I get "NSImageCell's object value must be an NSImage." and the app hangs. The same thing happens If I use a NSImageCell. If I return just a NSImage the image displays, but then I can't have any actions on it.

Any help would be greatly appreciated.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
What happens if you just return the image as the datasource return value?

Note that a table uses a single cell for all the rows in a given column, so your method would be leaking very badly. You want to define the cell once in the column for that table (not in the datasource method) and just return the image.
 

Stratoukos

macrumors member
Original poster
Jul 15, 2008
51
0
If I return just the image it displays normally inside the table view. Also [image isKindOfClass:[NSImage class]] returns true, so I'm sure it's an NSImage.

I could do that, but I want something to happen when a user clicks on the image, so I went with NSActionCell. I don't know if this is the "right" way to do it, but I can't think of something else.

You are, of course, right about the leak.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
I could do that, but I want something to happen when a user clicks on the image, so I went with NSActionCell. I don't know if this is the "right" way to do it, but I can't think of something else.

If you want something to happen when the user clicks on the cell, then you need to put the cell you want into that column. You could do it by creating a subclass (I have done that) or you could set the action and target for the cell itself (things you can do in Interface Builder). You might also investigate the delegate methods NSTableView has to offer, you might be able to work out a response from one of those. The other alternative is to just subclass NSTableView itself. Sometimes that is the best way to go.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.