2

NSTableViewで強調表示せずに太字の行選択スタイルを作成しようとしています

ハイライトをオフに切り替えました:

[myTable setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];

ただし、選択した行のテキストを太字にするのに問題があります。私が提案したように、NSTableViewのソースのプロパティを変更する必要があります。

- (void) tableViewSelectionDidChange: (NSNotification *) notification
{
    NSDictionary *boldFont = [NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:13.0]
                                                         forKey:NSFontAttributeName];
    NSDictionary *normalFont = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:13.0]
                                                         forKey:NSFontAttributeName];

    for(MyClass *obj in tableSourceList)
        obj.name = [[NSMutableAttributedString alloc]
                           initWithString:obj.name
                               attributes: normalFont];

    long row = [myTable selectedRow];
    MyClass objectAtSelectedRow = [tableSourceList objectAtIndex: row];
    objectAtSelectedRow.name = [[NSMutableAttributedString alloc]
                            initWithString:dr.dreamname
                                attributes: boldFont]; 
    [tableSourceList replaceObjectAtIndex:row withObject:objectAtSelectedRow];
}

残念ながら、効果はありません。

選択したときに行のテキストを太字にする方法は?

4

1 に答える 1

3

テーブルのデリゲートにレンダリングされるテーブルセルを変更することで、達成を試みることができます。

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
    // Maybe a test on the table column is recommanded if some cells should not be modified
    NSIndexSet *selection = [aTableView selectedRowIndexes];
    if ([selection containsIndex:rowIndex]) {
        [aCell setFont:[NSFont boldSystemFontOfSize:12]];
    } else {
        [aCell setFont:[NSFont systemFontOfSize:12]];
    }
}
于 2012-01-30T10:47:52.240 に答える