你在哪裏託管這個定製+複合NSCell子類?
-setHighlighted:是不是你在找什麼。從文檔:
默認情況下,此方法什麼也不做。 的NSButtonCell類重寫此 方法與由 NSCellLightsByBackground, NSCellLightsByContents,或 NSCellLightsByGray指定的 外觀繪製按鈕。
通常,單元格的主視圖將設置單元格的背景樣式,單元格將在繪製時使用該單元格來適當地顯示其自身。將背景樣式從主單元傳播到子單元。
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSRect textRect, popUpRect;
NSDivideRect(cellFrame, &textRect, &popUpRect, NSWidth(cellFrame)/2, NSMinXEdge);
/* Draw the text cell (self) */
[super drawInteriorWithFrame: textRect inView: controlView];
/* Draw our compound popup cell - create & release every time drawn only in example */
NSPopUpButtonCell *popUpCell = [[NSPopUpButtonCell alloc] initTextCell: @"popup title"];
[popUpCell setBordered: NO];
[popUpCell setBackgroundStyle: [self backgroundStyle]];
[popUpCell drawWithFrame: popUpRect inView: controlView];
[popUpCell release];
}
如果您在NSTableView中託管此複合單元,那應該足以獲得所選行的正確背景。
如果您以您自己的觀點託管此視圖,則可能需要執行其他工作。 (在提供建議之前,需要提供有關主機環境的其他詳細信息。)
這正是我所需要的。謝謝吉姆。 – 2009-07-24 20:31:33