Re: NSTreeController ChildKeyPath
Re: NSTreeController ChildKeyPath
- Subject: Re: NSTreeController ChildKeyPath
- From: Keith Blount <email@hidden>
- Date: Fri, 29 Jul 2005 16:36:12 -0700 (PDT)
Sorry, yes, Marcus is right - I completely misread
your e-mail and answered a question you did not ask.
The leaf key path should be bound to a BOOL, which was
what I was talking about (not what you asked), but as
Marcus pointed out, the child key path should be bound
to an array. The model object I use for
NSTreeController has an NSMutableArray *children bound
to this path (and a BOOL isLeaf variable bound to the
leaf key path). (The NSTreeController content itself
can be bound to a basic NSMutableArray that holds
these objects, and the object class set in attributes
in the inspector.)
For my own model, I have objects that return YES for
isLeaf contain a reference to self in their children
array and nothing else - but this is only because I
have an NSArrayController controlling a table view
bound to the NSTreeController's selection, and I want
the table view to display the selected object in the
outline view when a leaf is selected (and the children
array when a non-leaf is selected).
Actually, though, after a lot of experimentation and
getting a lot working, I have given up on
NSTreeController and returned to the old datasource
methods. Bear in mind that there is no way of doing
automatic state-saving and drag and drop (in my
experience) behaves very strangely with
NSTreeController. It is excellent for basic outline
views that don't need to do anything complicated,
though.
Anyway, sorry about my earlier confusion, hope that
this correction is at least of some use.
All the best,
Keith
--- "Marcus S. Zarra" <email@hidden> wrote:
> I am unfortunately not at my OSX machine right now
> but this advise does not
> sound right. As I recall there is a binding for leaf
> and another binding for
> children. Two different things. The ChildKey binding
> expects to receive an
> array of children back and the leaf binding expects
> to receive a Bool.
>
> The tree controller expects to be dealing with one
> object as near as I can
> tell. What I did to get it working for me was set up
> an abstract parent
> object that both my branches and leaves extended
> from. This is assuming of
> course that you have multiple types of objects you
> want the tree controller
> to handle. The parent object has two methods:
> (Bool)isLeaf and (NSArray
> *)children. The branch objects extended the parent,
> returned YES for isLeaf
> and returned an NSArray of all of it's children. The
> leaf objects returned
> NO for isLeaf and returned nil for children.
>
> Hope this helps and let me know if anything doesn't
> make sense.
>
> Marcus
>
> On 7/29/05, Keith Blount <email@hidden>
> wrote:
> >
> > Hello,
> >
> > You just need a BOOL instance variable such as
> BOOL
> > isLeaf, which is set to YES if you want the item
> to be
> > a leaf, and NO if it is a group. Then in the
> > NSTreeController's bindings, bind this variable to
> the
> > Child Key Path.
> >
> > Not sure how this will help you find a specific
> object
> > though. For finding specific objects you will
> probably
> > need to write a recursive method that traverses
> the
> > tree to find what you are looking for.
> >
> > Hope that is of some help.
> > Cheers,
> > Keith
> >
> > --- ORIGINAL MESSAGE: ---
> >
> > Can anyone explain in more detail than the apple
> > documentation how
> > the ChildKeyPath works for traversing a
> > NSTreeController? I need to
> > find a specific object, and it would appear this
> is
> > how I do it.
> > Each of my objects implements items (they return
> nil
> > because every
> > object is a leaf, i.e. no children).
> >
> > Thanks,
> >
> > Ben Dunton
> >
> >
> >
> >
> ____________________________________________________
> > Start your day with Yahoo! - make it your home
> page
> > http://www.yahoo.com/r/hs
> >
> > _______________________________________________
> > Do not post admin requests to the list. They will
> be ignored.
> > Cocoa-dev mailing list (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
>
> >
> > This email sent to email@hidden
> >
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden