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

这一生的挚爱 提交于 2019-12-09 23:41:03

问题


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 normal cell but the tableview get frozen after I add a cell with NSButtonCell type (for checkbox). How to fix it ?

Any help would be appreciated.


回答1:


According to the NSButtonCell reference, you can only specify a background color for borderless buttons. Have you tried to use borderless button cells ?

Moreover, I cannot find setDrawsBackground: method for NSButtonCell; I can only find it for NSTextFieldCell. Have you tried to remove the call ?



来源:https://stackoverflow.com/questions/2062605/how-to-set-background-color-of-cell-with-nsbuttoncell-type-in-nstableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!