What I want to do is basically explained in the subject, I want to set the background colour of a table column to be different from the other columns in the table.
I have been told here to use:
-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; and that is working fine on the same table to set custom text colours, however it isn't working correctly for setting the background.
Below is my code.
I have been told here to use:
-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex; and that is working fine on the same table to set custom text colours, however it isn't working correctly for setting the background.
Below is my code.
Code:
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex{
if([aTableView isEqualTo:spellClassLevelTable]){
if(![aCell isKindOfClass:[NSTextFieldCell class]]){
return;
}
if(![aCell respondsToSelector:@selector(setTextColor:)]){
NSLog(@"error, cell doesn't respond to selector setTextColor:");
return;
}
if(![aCell respondsToSelector:@selector(setBackgroundColor:)]){
NSLog(@"error, cell doesn't respond to selector setBackgroundColor:");
}
//if the current cell is in the selectedRow and the table is the first responder it should go white.
if([aTableView selectedRow]==rowIndex && [[[aTableView window] firstResponder] isEqualTo:aTableView]){
[aCell setTextColor:[NSColor whiteColor]];
}else{
[aCell setTextColor:[divArcOrDom transformedValue:[[spellClassController arrangedObjects] objectAtIndex:rowIndex]]];
}
if([aTableColumn isEqualTo:[[spellClassLevelTable tableColumns] objectAtIndex:0]]){
[aCell setBackgroundColor:[NSColor erLightGrayColor]];
}else{
[aCell setBackgroundColor:[NSColor yellowColor]];
}
}
}