gcstr
gcstr

Reputation: 1537

How to change style for nodes in NSOutlineView?

I am trying to figure out how to change the style for group nodes in NSOutlineView. With setSelectionHighlightStyle I can change the whole list style. But I want to change only the style for group nodes. How can I do that?

Upvotes: 2

Views: 978

Answers (2)

Quinn Taylor
Quinn Taylor

Reputation: 44769

When I ran into a similar problem, the method @Benedict mentions was never triggered for me. This is because NSOutlineView has a separate method:

- (void) outlineView:(NSOutlineView*)aTableView
     willDisplayCell:(id)aCell
      forTableColumn:(NSTableColumn*)aTableColumn
                item:(id)item;

See the documentation for the NSOutlineViewDelegate protocol. (This formal protocol is new in 10.6 — in previous versions of OS X, the methods were implemented as a category on NSObject.)

Upvotes: 3

Benedict Cohen
Benedict Cohen

Reputation: 11920

NSOutlineView is a subclass of NSTableView. Implement the tableView:willDisplayCell:forTableColumn:row: in the NSOutlineView delegate.

In the tableView:willDisplayCell:forTableColumn:row: implement something like this:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
    if ([aTableView isGroupRow: rowIndex]) {
        //modify aCell
    }


}

Upvotes: 3

Related Questions