2010-01-14 59 views
1

這是我的表視圖代表:如何在NSTableView中使用NSButtoncell類型設置單元格的背景顏色?

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)tableColumn row:(int)row 
{ 
    id theRecord; 
    NSMutableString *gid; 

    theRecord = [tableDataSource objectAtIndex:row]; 
    gid = [theRecord objectForKey:@"gid"]; 

    if (([gid intValue] % 2) != 0) 
    { 
     [aCell setDrawsBackground: YES]; 
     [aCell setBackgroundColor: [NSColor colorWithCalibratedRed: 237.0/255.0 
                  green: 243.0/255.0 
                   blue: 254.0/255.0 
                  alpha: 1.0]]; 

    } 
    else 
    { 
     [aCell setDrawsBackground: NO]; 
    } 
} 

它正常工作後,我添加單元格與NSButtonCell類型(複選框)顯示正常細胞,但得到凍結的tableview。如何解決它?

任何幫助,將不勝感激。

回答

1

根據NSButtonCell reference,您只能爲無邊界按鈕指定背景顏色。你有沒有嘗試使用無邊界按鈕單元格?

此外,我找不到setDrawsBackground:方法NSButtonCell;我只能找到NSTextFieldCell。您是否嘗試刪除該通話?

+0

我的歉意,我是新來的可可。需要更頻繁地閱讀文檔。謝謝! – Irwan 2010-01-15 02:20:02

相關問題