Search code examples
swiftcocoansoutlineview

How to handle Check Box clicks in a cell based NSOutlineView


I'd like to handle clicks on check boxes in NSOutlineView. Check boxes are Check Box Cell of type NSButtonCell. I'm able to set the initial state in:

optional func outlineView(_ outlineView: NSOutlineView,
                            willDisplayCell cell: AnyObject,
                            forTableColumn tableColumn: NSTableColumn?,
                            item item: AnyObject)

Now, how can i execute a function when the state of the check box changes? I searched the internet but i can't find out.


Solution

  • I found this to set values from the table:

    DragNDropOutlineView: implementing drag and drop in an NSOutlineView

    // Optional method: needed to allow editing.
    - (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  {
    AAPLSimpleNodeData *nodeData = [item representedObject];
    
    // Here, we manipulate the data stored in the node.
    if ([[tableColumn identifier] isEqualToString:COLUMID_IS_SELECTABLE]) {
        nodeData.selectable = [object boolValue];
    }
    

    }

    Another way is to set target and action of each cell in:

    optional func outlineView(_ outlineView: NSOutlineView,
                            willDisplayCell cell: AnyObject,
                            forTableColumn tableColumn: NSTableColumn?,
                            item item: AnyObject)