Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSTableview更改高光颜色_Objective C_Macos_Cocoa_Nstableview - Fatal编程技术网

Objective c NSTableview更改高光颜色

Objective c NSTableview更改高光颜色,objective-c,macos,cocoa,nstableview,Objective C,Macos,Cocoa,Nstableview,我正在开发一个MAC应用程序,包括tableView。 要将所选行的颜色更改为黄色。在表视图中设置此选项: [yourtableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; 并将NSTableView的以下委托方法实现为: - (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(N

我正在开发一个MAC应用程序,包括tableView。
要将所选行的颜色更改为黄色。

在表视图中设置此选项:

[yourtableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
并将NSTableView的以下委托方法实现为:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
    if ([[aTableView selectedRowIndexes] containsIndex:rowIndex]) 
    {
       [aCell setBackgroundColor: [NSColor yellowColor]];   
    } 
    else 
    {
       [aCell setBackgroundColor: [NSColor whiteColor]];
    } 
    [aCell setDrawsBackground:YES];
}  

如果只想高亮显示列的单个单元格,请执行如下操作:-

- (void)tableView:(NSTableView *)tableView
  willDisplayCell:(id)cell
   forTableColumn:(NSTableColumn *)tableColumn
              row:(NSInteger)row
{
    if ([[tableColumn identifier] isEqualToString:@"yourColumm"])
    {
        [cell setBackgroundColor:[NSColor yelloColor]];
    }
}

这可能会有帮助-谢谢你。。。我会试试这个…:)假设你说的是一个基于单元格的表,这与上一个答案的原因不同,除非你的单元格恰好没有任何填充(甚至可能没有填充)。要更改行高光,请覆盖表的HighlightSelectionCliprect:方法并自己绘制背景色,如下所示:所选行中单元格的背景完全被行高光覆盖,因此,据我所知,设置单元格的背景色根本不会更改单元格的外观。