How to set text color in a NSPopupButtonCell in an NSTableView

Joined
Mar 19, 2009
Messages
1
Reaction score
0
Points
1
This seems like it should be simple but for some reason I can not get it to work. I've tried a million different things with no success. All I want to do is set the color of the text in a NSPopUpButtonCell. One of my columns in an a subclass of NSTableView contains popup menus. Everything is working great so I move on to the last issue (I hope). I need to be able to set the color of the menu items based on certain criteria. But before I got to that I just tried to change the color from black to anything else. It just doesn't work. Below is the relevant code from my project. I don't usually post this much code but this is killing me and I was hoping someone might be able to spot something I am doing wrong and set me straight. Thanks in advance for any help. Basically, I just have subclasses of NSTableView, NSPopupButtonCell and NSTableColumn. I've stripped out all the junk not relevent to this problem.



********************* NSTableView Subclass ****************************

@interface ListBoxControl : NSTableView {
MyDataSource *TheDataSource;
myButtonCellClass *pcell;
}
- (void)awakeFromNib;
-(MyDataSource*) getDataSource;
-(myNSCell*) getCustomPCell;

@end


@implementation ListBoxControl

- (void)awakeFromNib;
{
NSAttributedString *redString;
NSMenu *colorMenu;
NSMenuItem *theRedItem;
NSMutableDictionary *red_attrs;


TheDataSource = [[MyDataSource alloc] init];
[TheDataSource retain];
[TheDataSource initData];
[TheDataSource setHostView:self];
[self setDataSource:TheDataSource];

red_attrs = [NSMutableDictionary dictionaryWithCapacity:2];
[red_attrs setValue:[NSColor redColor] forKey:mad:"NSForegroundColorAttributeName"];
[red_attrs setValue:[NSColor redColor] forKey:mad:"NSStrokeColorAttributeName"];

redString = [[[NSAttributedString alloc] initWithString:mad:"Red" attributes:red_attrs] retain];

colorMenu = [[NSMenu alloc] initWithTitle:mad:"COLORMENU"];
theRedItem = [[NSMenuItem alloc] initWithTitle:mad:"Title1" action:NULL keyEquivalent:mad:""];
[theRedItem setAttributedTitle:redString];
[colorMenu addItem: theRedItem];


pcell = [[[myButtonCellClass alloc] initTextCell:mad:"" pullsDown:false] retain];
[pcell setEditable:NO];
[pcell setBordered:NO];
[pcell setMenu:colorMenu];

}


-(myNSCell*) getCustomPCell
{

return pcell;
}

-(MyDataSource*) getDataSource
{
return TheDataSource;
}
@end



********************* NSPopUpButtonCell Subclass ****************************

@interface myButtonCellClass : NSPopUpButtonCell {

}

@end

@implementation myButtonCellClass

@end



********************* NSTableColumn Subclass ****************************
@interface customColumn : NSTableColumn {

}
- (id)dataCellForRow:(NSInteger)row;
@end

@implementation customColumn
- (id)dataCellForRow:(NSInteger)row
{
return [[self tableView] getCustomPCell];
}

@end
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top