Re: setContent: vs bind:toObject:withKeyPath:options: ?
Re: setContent: vs bind:toObject:withKeyPath:options: ?
- Subject: Re: setContent: vs bind:toObject:withKeyPath:options: ?
- From: Keith Blount <email@hidden>
- Date: Wed, 28 Dec 2005 11:27:14 -0800 (PST)
Many thanks for your reply, much appreciated.
I'm only surprised because it seems to work
differently in NSArrayController and NSTreeController
(and I had thought that -setContent: should in fact
set the "contentArray" binding). This whole issue
arose because I wanted to avoid the retain loop caused
by binding to file's owner described here:
http://theobroma.treehouseideas.com/document.page/18
(And in many other places too.)
As the workaround states there, calling -setContent:
on an NSArrayController after the nib has loaded
resolves this issue, and everything works as expected.
For instance, if I call [arrayController
setContent:myArray], I can then archive myArray in my
document and reload it on reopen. That is to say,
myArray is populated by the NSArrayController after
calling -setContent:. If I -add: to my arrayController
and then peek inside myArray using an NSLog(), I can
see that myArray has been populated as expected.
However, this does *not* seem to work the same with
NSTreeController. If I do exactly the same thing with
an NSTreeController, calling [treeController
setContent:myTreeArray] after the nib has loaded, then
the treeController does *not* populate myTreeArray. In
fact, it seems to do nothing at all. If I -add: some
objects to my tree controller and then peek inside
myTreeArray, there is nothing there. Only
-bind:toObject:withKeyPath:options: works in this
case.
There must be something I'm missing. I have it
working, but I am curious as to the reason for the
difference. NSTreeController seems very "buggy" to me
anyway (or at least, overly opaque), so maybe this is
just another quirk.
Thanks again,
Keith
--- Camillo Lugaresi <email@hidden> wrote:
>
On 28/dic/05, at 16:46, Keith Blount wrote:
>
> I have several NSArrayControllers, and to bind
>
their
>
> contents programmatically, all I have to do is
>
call
>
> -setContent:. However, this does not seem to work
>
with
>
> NSTreeController.
>
>
It doesn't work with NSArrayController, either.
>
Setting the content
>
is not the same as binding the content property:
>
when you do the
>
former, you hand the controller an array and it adds
>
and removes
>
objects directly; when you do the latter, it uses KV
>
accessors to ask
>
the object to which it is bound to manipulate the
>
property whose key
>
is specified in the binding. At least, that's how
>
I'm using it. :-)
>
>
> After trying various different
>
> approaches, I finally realised that the only way
>
to
>
> bind the content of an NSTreeController
>
> programmatically was by calling [treeController
>
> bind:@"contentArray" toObject:self
>
> withKeyPath"rootNodes" options:nil].
>
>
I don't have much experience with Cocoa bindings,
>
but I'm pretty sure
>
that the bind:toObject:withKeyPath:options: method
>
is the normal way
>
to establish bindings programmatically. Why are you
>
so surprised that
>
in order to set up a binding you have to call a
>
method called "bind"?
>
>
Camillo
>
__________________________________
Yahoo! for Good - Make a difference this year.
http://brand.yahoo.com/cybergivingweek2005/
_______________________________________________
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