Search code examples
objective-ccocoadata-bindingnsoutlineview

Why is my header selectable and the cell not editable


I have two questions related to NSOutlineView:

  1. Why is my Header selectable even though I tell it that it is a Group (otherwise it would not have the "Hide" on the right:

    enter image description here

    // I am telling the view that the given item is a group by implementing
    -(BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item;
    
  2. I am using a view-based outline and so I can't press Enter or click on a leaf to edit it. Is there a simple way (with the default view-based setup so achieve this functionality).

    Please note that I tried to achieve this by binding to editable on the given column. But the method is never called.


Solution

  • At least I was able to answer the first part of my own question.

    I had to implement the method like so in order to make the header unselectable:

    - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item{
        // Add your own logic here to determine whether a cell should be selectable 
        return ![self isHeader:item];
    }
    

    I have created a little sample project that does the following.

    • 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