How do i make a simple view-based NSOutlineView?

后端 未结 4 1082
既然无缘
既然无缘 2021-02-05 21:40

For learning purposes i would like to convert a cell-based NSOutlineView to a view-based one,

basically i would like the following:

  • instead of a normal ce
4条回答
  •  太阳男子
    2021-02-05 22:30

    To return view to OutlineView column Instead of using datasource method that return objectValue:

    - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)theColumn byItem:(id)item
    

    USE THE DATASOURCE METHOD THAT RETURN VIEW!!!!!!!!:

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

    everything else is the same(minimal req is the first three datasource methods, you don't need the delegate methods) but, you can't use willdisplaycell its called only for cell based , do everything to the view in the viefortablecolumn method like this:

    if ([[tableColumn identifier] isEqualToString:@"YourColumnIdentifier"]){
        NSTableCellView *cell = [outlineView makeViewWithIdentifier:@"YourViewsIdentifier" owner:self];
        [cell.textField setStringValue:[(YourItem *)item name]];
        [cell.imageView setImage:[(YourItem *)item image]];
        return cell;
    }
    
    return nil;
    

    and don't forget to set identifiers , and to set the OutlineView to be View Based(in IB ...).

提交回复
热议问题