Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View-based NSOutlineView header cell font issues

I'm currently trying to use a new view-based NSOutlineView in my Cocoa app. As I'm not using bindings, so I implemented all required delegate and datasource methods in my controller.

In interface builder I've added a NSOutlineView with a highlighting set to SourceList and Content Mode set to View Based. Thus, there were two default table cell views provided (one Header cell with HeaderCell set as identifier and one data cell with DataCell set as identifier)

This is what it looks like in interface builder, header cell views correctly show a grey-blue textField while data cell views have a image view and a textField with correct color and font settings

To provide the views, I use the following code, to return a DataCell-view or a HeaderCell-view and set the textField of the cell accordingly, based on the corresponding identifier set in interface builder.

- (NSView *)outlineView:(NSOutlineView *)outlineView 
     viewForTableColumn:(NSTableColumn *)tableColumn 
                   item:(id)item {


    NSTableCellView *result = nil;

    if ([item isKindOfClass:[NSMutableDictionary class]]) {
        result = [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];

        id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : groupedRoster;
        [[result textField] setStringValue:[[parentObject allKeys] objectAtIndex:0]];


    } else {
        result = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];

        [item nickname] ? [[result textField] setStringValue:[item nickname]] : [[result textField] setStringValue:[[item jid] bare]];
    }
    return result;
}

Running everything it looks like the following.

Could anybody provide me with hints, to why the header cell is neither bold, nor correctly colored, when selected?

like image 589
BinaryBucks Avatar asked Aug 17 '11 17:08

BinaryBucks


2 Answers

You need to implement the -outlineView:isGroupItem: delegate method and return YES for your header rows. That will standardize the font and replace the disclosure triangle on the left with a Show/Hide button on the right. You will still need to manually uppercase your string to get the full effect.

I'm not sure if the group row delegate method above makes the selection style look okay or not. However, you normally don't want the header rows to be selectable at all in source lists, which you by returning NO for header items from the -outlineView:shouldSelectItem: delegate method.

like image 125
Boaz Stuller Avatar answered Sep 23 '22 23:09

Boaz Stuller


I have created a little sample project which includes a source list and also uses the -outlineView:isGroupItem: method as @boaz-stuller has suggested.

  • Display a list of items
  • Edit the items in a master-detail fashion
  • Remove and add items
  • Usage of bindings

Check out besi/mac-quickies on github. Most of the stuff is either done in IB or can be found in the AppDelegate

screenshot

like image 33
Besi Avatar answered Sep 26 '22 23:09

Besi