2012-04-22 9 views
2

テーブルの列をサブクラス化してNStextFieldCellにします。与えられたコードで列の色を変更したい場合、色は変わりません。どうして?サブクラス化した列の色を変更できません

- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row 
{ 
    if(row%2==0) 
     [cell setBackgroundColor:[NSColor knobColor]]; 
    else 
     [cell setBackgroundColor:[NSColor lightGrayColor]]; 

    [cell setDrawsBackground: YES]; 
} 

私は

- (NSRect)titleRectForBounds:(NSRect)theRect 
{ 
    NSRect titleFrame = [super titleRectForBounds:theRect]; 
    NSSize titleSize = [[self attributedStringValue] size]; 
    titleFrame.origin.y = theRect.origin.y + (theRect.size.height - titleSize.height)/2.0; 
    return titleFrame; 
} 

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView 
{ 
    NSRect titleRect = [self titleRectForBounds:cellFrame]; 
    [[self attributedStringValue] drawInRect:titleRect]; 
} 

答えて

1

試しNSTextFieldCellサブクラスでこのコードを使用します。それはiOSのOSXではないので

[cell contentView] setBackgroundColor:[NSColor redColor]]; 
+0

ないUIColorが、NSColor、。 –

+0

'willDisplayCell'でそれを使用しています(実行時にエラーが発生すると、テーブルに行が表示されないことを意味します) –

+0

どのようなエラーが発生しましたか?テーブルには何行ありますか?ログ/画面? – demon9733

関連する問題