如何在 NSTableView 中设置 NSButtoncell 类型的单元格的背景颜色?
这是我的表视图委托:
- (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];
}
}
它可以很好地显示正常单元格,但在我添加 NSButtonCell 类型的单元格(用于复选框)后,表视图会被冻结。如何修复它?
任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 NSButtonCell 参考< /a>,只能为无边框按钮指定背景颜色。您是否尝试过使用无边框纽扣电池?
此外,我找不到 NSButtonCell;我只能找到它 NSTextFieldCell。您是否尝试过删除通话?
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 ?