NSTreeController selection (probably a silly mistake)

  • I am trying to access the currently selected object in an
    NSOutlineView who's content is bound to arrangedObjects of an
    NSTreeController.

    The NSTreeController contentObject is bound to an object in
    MyDocument (through File's Owner) which has children and isLeaf
    accessors tied properly to the tree controller. This all works fine
    and my hierarchy shows up when I bind a column to displayName. Happy.

    Now, I am trying to enable a button based on the bool value (actually
    NSNumber numberWithBool) returned from a "canAddNew" accessor of the
    selected object in the outline view. Interface Builder settings are:

    Bind to: NSTreeController
    Controller key: selection
    Model Key Path: canAddNew

    This doesn't work. I've been reading through documentation to see
    what obvious thing I'm missing but I just can't find it. During
    initialization of each object I send a setCanAddNew message. Logging
    shows that the variable has been set. However, my button never
    becomes enabled no matter what the Outline view selection is.

    In fact, I can't get responses from selection from anything for any
    binding. (target,argument enabled, hidden for any controls). If I
    bind to a text fields value, it stays disabled with "No Selection" in
    it. Obviously I'm missing something. Could someone point me at the
    right model key path?

    Thanks!

    --Derrek

    P.S. -- For a variety of reasons, I can't use the NSTreeController's
    implementation of canAdd. So I'm rolling my own.
  • Hi Derrek,

    On Oct 10, 2006, at 4:26 AM, Derrek Leute wrote:

    >
    > I am trying to access the currently selected object in an
    > NSOutlineView who's content is bound to arrangedObjects of an
    > NSTreeController.

    did you use the 'content'-binding of the NSOutlineView? You need to
    bind 'selectionIndexPaths' too.
    This is done automatically if you bind to a NSTableColumn. See
    <http://developer.apple.com/documentation/Cocoa/Reference/
    CocoaBindingsRef/BindingsText/NSOutlineView.html#//apple_ref/doc/uid/
    NSOutlineView-DontLinkElementID_305
    > for the documentation. Otherwise
    the
    selection of the NSOutlineView and NSTreeController is not in sync ...

    Cheers,

    felix
  • I did bind the content binding. And I just unbound it and everything
    is working right!

    That leads me to the question of what is the benefit of having a
    content binding? (I did it because that's how the NSXML Tree
    Controller example did it) Does it exist so you can bind sort
    descriptors rather than using the "Create Sort Descriptors" check box
    on the column binding? (and selection index paths)

    Thanks a lot!

    --Derrek

    On Oct 10, 2006, at 7:21 AM, Felix Franz wrote:

    > Hi Derrek,
    >
    > On Oct 10, 2006, at 4:26 AM, Derrek Leute wrote:
    >
    >>
    >> I am trying to access the currently selected object in an
    >> NSOutlineView who's content is bound to arrangedObjects of an
    >> NSTreeController.
    >
    > did you use the 'content'-binding of the NSOutlineView? You need to
    > bind 'selectionIndexPaths' too.
    > This is done automatically if you bind to a NSTableColumn. See
    > <http://developer.apple.com/documentation/Cocoa/Reference/
    > CocoaBindingsRef/BindingsText/NSOutlineView.html#//apple_ref/doc/
    > uid/NSOutlineView-DontLinkElementID_305> for the documentation.
    > Otherwise the
    > selection of the NSOutlineView and NSTreeController is not in sync ...
    >
    >
    > Cheers,
    >
    >
    > felix
    >
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today