这种方法应该可行。这是从内存中,所以没有保证,但是快速的样机似乎给您正在寻找的结果:
// Outline view delegate
-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item {
NSUInteger rowNo = [outlineView rowForItem:item];
NSColor *backgroundColor;
if ([[outlineView selectedRowIndexes] containsIndex:rowNo]) {
backgroundColor = // Highlighted color;
}
else {
backgroundColor = // Normal background color;
}
[cell setBackgroundColor: backgroundColor];
}
在你的情况下,你当然只适用于与钮扣电池列单元格的背景颜色。
这是所使用的钮扣电池,在outlineView:dataCellForTableColumn:item:
创建。
NSButtonCell *cell = [[NSButtonCell alloc] init];
[cell setBezelStyle:NSRegularSquareBezelStyle];
[cell setButtonType:NSToggleButton];
[cell setBordered:NO];
[cell setTitle:@""];
[cell setImage:[NSImage imageNamed:@"green.png"]];
[cell setAlternateImage:[NSImage imageNamed:@"red.png"]];
[cell setImagePosition:NSImageOverlaps];
你或许可以通过创建自己的细胞后裔并在那里做绘图来解决这个问题。这样,您可以更容易地绘制如何在其中绘制内容(例如,多个图像,徽章,不同的文本颜色等)。 –
我认为所讨论的大纲视图是基于单元格的。基于查看的表格视图(因此也提供了大纲视图)提供了绘制背景的方法(尽管您需要在文档中进行挖掘),但是您将失去以相同方式使用绑定的能力,所以不知道它是否值得。 – Monolo
可能有东西在这里,虽然:http://stackoverflow.com/questions/2062605/how-to-set-background-color-of-cell-with-nsbuttoncell-type-in-nstableview – Monolo