How to set cell background color with type NSButtoncell in NSTableView?

This is my table view delegate:

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
    id theRecord;
    NSMutableString *gid;

    theRecord = [tableDataSource objectAtIndex:row];
    gid = [theRecord objectForKey:@"gid"];

    if (([gid intValue] % 2) != 0)
    {
        [aCell setDrawsBackground: YES];
        [aCell setBackgroundColor: [NSColor colorWithCalibratedRed: 237.0 / 255.0
                                                             green: 243.0 / 255.0
                                                              blue: 254.0 / 255.0
                                                             alpha: 1.0]];

    }
    else
    {
        [aCell setDrawsBackground: NO];
    }
}

It works fine to display a normal cell, but the tableview will freeze after adding a cell with type NSButtonCell (for checkbox). How to fix it?

Any help would be appreciated.

+1
source share
1 answer

According to the NSButtonCell link, you can only specify the background color for borderless buttons. Have you tried using buttons with borderless cells?

Also, I cannot find a method setDrawsBackground:for NSButtonCell ; I can only find it for NSTextFieldCell . Did you try to delete the call?

+1
source

All Articles