Johnny Johnny - 11 months ago 217
Objective-C Question

NSTableRowView/NSTableCellView how to set custom color to selected row?

I am trying to implement custom row color when table row is selected.

-(void)tableViewSelectionDidChange:(NSNotification *)notification{

NSInteger selectedRow = [_mainTable selectedRow];

NSTableCellView *cell = [_mainTable rowViewAtRow:selectedRow makeIfNecessary:NO];

cell.layer.backgroundColor = [NSColor redColor].CGColor;


But this is not working. I find that Apple documentation very confusing (maybe I am wrong). I am not experienced with Mac programming.

Can someone suggest any solution? Basically I need that selection Color to be transparent.

Answer Source

first set tableview selection highlight style to


then in your tablView delegate implement


and write this code inside it:

UITableViewRow *row= [_mainTable rowViewAtRow:selectedRow makeIfNecessary:NO];
row.backgroundColor = [your color];
return YES;

read these also

for selection style