質問

私はnStableビュー1の次のプロパティを変更する必要があります1-色の変更:選択したときに行の色とテキストの色 - テキストの色を変更します。

各行のTextColorを変更するには、Delegateメソッド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:]:インスタンスに送信された認識されていないセレクターがテキストフィールドセルを設定する必要がある場所のように見えますが、わかりません。 、親切に助けてください、

別のことは、最初はセルの背景は必要ありませんが、セルが選択されたら、背景を変更する必要があるか、ハイライトの色を言うことができるかもしれません。

役に立ちましたか?

解決

これをやってからしばらく経ちましたが、私はそれをする必要があるときに、コービン・ダンによるこのブログ投稿をいつも参照してください: cocoa:nstableviewのwilldisplaycellデリゲートメソッド、[nscell settextcolor]、および「ソースリスト」

ちなみに、CorbinはAppleで働いており、私が理解していることから、NstableViewの責任があります。彼がココアについてブログを書いているとき、私はいつもそれをブックマークしてください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top