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?
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];
}
Try this in your rowViewForItem method. It reloads and redisplays the data for item.
- (void)reloadItem:(id)item;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With