Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload a custom NSTableRowView in NSOutlineView?

I'm trying to modify the appearance of a custom NSTableRowView used in my NSOutlineView when the row expands/collapses. My NSOutlineViewDelegate includes:

- (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];
}

This unfortunately doesn't reload the custom row view.

Reloading data for the entire NSOutlineView works:

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

But with large amounts of data this can be time consuming, and often leads to a spinning beach ball.

Is it possible to reload the custom row view for just a single top-level item?

like image 334
JM NZ Avatar asked Nov 02 '13 05:11

JM NZ


2 Answers

Try the following method:

-(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];
}

You can advance this further to get the row object, and then determine which color you want for a particular row.

-Edit-

If you wish to alter the parent cell view to show that it has been expanded you have implemented the wrong method for the NSOutlineview. Implement the method like the following:

-(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];
}
like image 56
Just a coder Avatar answered Nov 15 '22 10:11

Just a coder


Try this in your rowViewForItem method. It reloads and redisplays the data for item.

    - (void)reloadItem:(id)item;
like image 44
Hussain Shabbir Avatar answered Nov 15 '22 08:11

Hussain Shabbir