如何在NSTableView中突出显示一行

时间:2009-09-24 18:22:18

标签: cocoa nstableview

我的应用程序中有NSTableView。现在说是8列乘48行。

我有一个运行特定特定列的函数,以查看每个单元格中的值是否大于某个值。如果是,我希望应用程序突出显示该行。

我做了一些阅读,我仍在寻找函数调用或一个让我提取单元格/行/或矩形的过程,让我改变颜色。

更改细胞颜色的功能和步骤是什么?

5 个答案:

答案 0 :(得分:5)

- [NSTableView selectRowIndexes:byExendingSelection:]

Source

答案 1 :(得分:3)

要更改单元格的颜色,可以尝试使用此方法

-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
   [cell setDrawsBackground:YES];
  if(row==0)
       [cell setBackgroundColor:[NSColor color];
   else if(row==1||row==2)
        [cell setBackgroundColor:[NSColor color];
    else
        [cell setBackgroundColor:[NSColor color];
}

这会使你的行有不同的颜色。

答案 2 :(得分:0)

设置tableView委托并实现

– tableView:dataCellForTableColumn:row:

方法。然后编写一个自定义的dataCell类来进行自定义绘图。

答案 3 :(得分:0)

如果您将数据提取为字符串,则可以使用: -

NSAttributedString

更改文字和背景的颜色。

答案 4 :(得分:0)

-(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

...为您提供预先制作的单元格(通常是NSTextFieldCell),然后您可以对其进行着色。不需要退货 - Apple已经制作并即将使用它,只需根据您的需要修改对象即可。效果很好。

相关问题