Binding view-based NSOutlineView to Core Data

前端 未结 4 740
栀梦
栀梦 2021-01-31 11:26

I\'m trying to implement the new view-based OutlineView as a source list in my Mac app. I can\'t get values to display, though, so I made a small test app from the Core Data app

4条回答
  •  梦如初夏
    2021-01-31 12:11

    As Boaz noted above, you need to implement the Delegate method to return a view.

    Quite a mystery considering I could not find that method in the Docs.

    Regarding the type of the (id)item parameter, it's a NSTreeControllerTreeNode which is an undocumented subclass of NSTreeNode. If you cast it you can get the cell's object, and return different view based what kind of object is, or whatever attributes of that object determine the cell view type:

    - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
        NSTableCellView *view = nil;
    
        NSTreeNode *node = item;
    
        if ([node.representedObject isKindOfClass:[Group class]]) {
            view = [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
        } else {
            view = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
        }
    
        return view;
    }
    

提交回复
热议问题