我需要更改以下屬性以用於我的NSTable視圖 1 - 更改顏色:選擇其行時的行顏色和文本顏色 2 - 更改文本顏色對於其取決於的每一行一些輸入參數,NSTableView更改一行的文本顏色
爲了改變文字顏色的每一行,我應該重寫委託方法willDisplayCell,這是我做了什麼,到現在爲止,
- 創建表----
pMyTableView = [[[CustomTableView alloc] initWithFrame:clipViewBounds] autorelease];
NSTableColumn* firstColumn = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
[firstColumn setWidth:35];
[pMyTableView addTableColumn:firstColumn];
NSTableColumn* secondColumn = [[[NSTableColumn alloc] initWithIdentifier:@"secondColumn"] autorelease];
[secondColumn setWidth:180];
[pMyTableView addTableColumn:secondColumn];
[pMyTableView setRowHeight:30];
[self SetContactTableDisplayAttribute];
[pMyTableView setDataSource:self];
[scrollView setDocumentView:pOnLineCTView];
[pMyTableView setDelegate:self]
;
- - 其他委託方法-------------
- (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex{
if([pColName isEqualToString:@"secondColumn"])
{
// Here there is some logic , to get the proper string that i wanted to display
return @"tempString";
}
}
----現在,我這是怎麼設置的文本顏色---
- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex {
NSString *colName = [aTableColumn identifier];
if([colName isEqualToString:@"secondColumn"]){
NSTextFieldCell *pCell = aCell;
[pCell setTextColor:[NSColor blueColor]];
}
}
隨着上面的代碼,它在日誌中的異常,我可以看到行 - [NSCell setTextColor:]:無法識別的選擇器發送到實例 看起來像某處我需要設置文本字段單元格,但如何以及在哪裏我不知道, 請幫助我,
另一件事我s,最初我不需要任何細胞背景,但是一旦細胞被選中,那麼我也許需要改變背景,或者你可以說突出顯示顏色,我可以在WillDIsplayCell中獲得相同的效果
謝謝,讓我試試:) – Amitg2k12 2011-01-26 05:42:29