5

行の展開/折りたたみ時に NSOutlineView で使用されるカスタム NSTableRowView の外観を変更しようとしています。私の NSOutlineViewDelegate には以下が含まれます:

- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item
{
    ...
    return rowView;
}

- (void)itemDidExpand:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    id item = [userInfo objectForKey:@"NSObject"];
    NSOutlineView *outlineView = [notification object];
    [outlineView reloadItem:item];
}

残念ながら、これはカスタム行ビューをリロードしません。

NSOutlineView 全体のデータをリロードすると、次のように機能します。

- (void)itemDidExpand:(NSNotification *)notification
{
    [outlineView reloadData];
}

しかし、大量のデータの場合、これには時間がかかる可能性があり、多くの場合、ビーチ ボールが回転します。

単一の最上位アイテムのカスタム行ビューをリロードすることはできますか?

4

2 に答える 2

6

次の方法を試してください。

-(void)outlineView:(NSOutlineView *)outlineView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
    aColor = [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0];
    [view setBackgroundColor:aColor];
}

これをさらに進めて行オブジェクトを取得し、特定の行に必要な色を決定できます。

-編集-

親セル ビューを変更して展開されていることを示す場合は、NSOutlineview に間違ったメソッドを実装しています。次のようにメソッドを実装します。

-(void)outlineViewItemWillExpand:(NSNotification *)notification {
    id theObject = [[notification userInfo] objectForKey:@"NSObject"];

    NSInteger row = [theOutlineView rowForItem:theObject];
    NSTableRowView *theRowView = [theOutlineView rowViewAtRow:row makeIfNecessary:NO];

    int r = 110;
    int g = 110;
    int b = 110;

    NSColor *aColor = [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0];
    [theRowView setBackgroundColor:aColor];
}
于 2013-11-06T08:29:10.623 に答える
1

これを rowViewForItem メソッドで試してください。item のデータをリロードして再表示します。

    - (void)reloadItem:(id)item;
于 2013-11-02T07:33:30.647 に答える