如何在NSTableView中使用NSButtoncell类型设置单元格的背景颜色? [英] How to set background color of cell with NSButtoncell type in NSTableView?
问题描述
这是我的表视图委托:
- (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];
}
}
它可以正常显示正常单元格,但tableview get冻结后,我添加一个单元格与NSButtonCell类型(复选框)。如何解决?
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 ?
任何帮助将不胜感激。
推荐答案
根据 NSButtonCell参考资料,您只能为无边框按钮指定背景颜色。
According to the NSButtonCell reference, you can only specify a background color for borderless buttons. Have you tried to use borderless button cells ?
此外,我找不到 setDrawsBackground: http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Classes/NSButtonCell_Class/Reference/Reference.html =nofollow noreferrer> NSButtonCell ;我只能找到 NSTextFieldCell 。您是否已尝试移除通话?
Moreover, I cannot find setDrawsBackground:
method for NSButtonCell; I can only find it for NSTextFieldCell. Have you tried to remove the call ?
这篇关于如何在NSTableView中使用NSButtoncell类型设置单元格的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!