How can I change the 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 only want to change the style for the group nodes. How can i do this?

+2


source to share


2 answers


When I faced a similar issue, @Benedict's mention method never worked 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, methods were implemented as a category in NSObject.)

+3


source


NSOutlineView

is a subclass NSTableView

. Add tableView:willDisplayCell:forTableColumn:row:

to the delegate NSOutlineView

.

In tableView:willDisplayCell:forTableColumn:row:

implementing something like this:



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


}

      

+3


source







All Articles