views:

227

answers:

1

How would I use outlineView:isGroupItem: to give the root object in an NSOutlineView a Gradient background?

+3  A: 

You implement this in the outlineView's delegate.

One way of doing this:

- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
    if ([outlineView parentForItem:item]) {
        // If not nil; then the item has a parent.
        return NO;
    }
    return YES;
}

Here's a link to the docs.

Abizern
Thanks. I expected that to work, but oddly after putting the code in my data source my outline view doesn't change at all, meaning that the root item still doesn't have the gradient background. Odd.
Joshua
It's a delegate method, not a datasource method. Make sure that the tableview's delegate outlet is also connected to the datasource in this case.
Abizern
Ah. I see. I've put it in the Delegate now (http://snapplr.com/fvzs). But what do you mean by 'Make sure that the tableview's delegate outlet is also connected to the datasource in this case.'
Joshua
And it still doesn't work.
Joshua
Outline views have a delegate outlet as well as a datasource outlet. You need to hook up the delegate outlet to the class that implements this method in IB. I've just run this in a sample app and it works for me. http://embr.it/Ro
Abizern
Would you mind sending me a link to that Sample App?
Joshua
Add the method to a table delegate in this sample app. http://developer.apple.com/mac/library/samplecode/AbstractTree/
Abizern
Ah, I see. But how did you get the grey background not the default blue one?
Joshua
I'm not sure what you mean. Have you tried setting the highlight style of the outline view to be Regular instead of Source view?
Abizern
Don't worry it works. Thanks!
Joshua