Re: Binding to an array.name, how?
Re: Binding to an array.name, how?
- Subject: Re: Binding to an array.name, how?
- From: mmalcolm crawford <email@hidden>
- Date: Mon, 16 May 2005 11:42:39 -0700
On May 15, 2005, at 10:41 PM, Bob Ippolito wrote:
So the question is: How does NSPopUpButton allow or implement
binding its contentValues to an array.name, where name is a field
of the dictionary which is an element of array? (Hope that's
clear...)
This is just a guess, as I haven't tried it, but perhaps KVO only
works for arrays if you implement indexed accessors (countOfArray,
objectInArrayAtIndex:, insertObject:inArrayAtIndex:,
removeObjectFromArrayAtIndex:).
No, this applies to modifications to an array contained by another
object (indexed accessors ensure the correct KVO notifications are
sent when the array is modified -- see "Programmatic modifications to
arrays not noticed by table view", <http://homepage.mac.com/mmalc/
CocoaExamples/controllers.html>). The error here:
I've created my own subclass of NSController and called
exposeBinding for the various bindings available on it. Each
binding corresponds exactly with a KVC-compliant pair of methods
e.g. array and setArray.
Now I can easily bind arrays of simple values to the binding.
However, supposing I have an array of dictionaries, each
dictionary with a key of "name", I find I cannot bind to
array.name... it fails at runtime with a
[<NSCFArray 0x3b85e0> addObserver:forKeyPath:options:context:] is
not supported. Key path: name
is in setting up the observer (before you even get to the stage of
receiving KVO notifications). You can't simply observe the array
keypath, you need to register to observe the objects in the array
(see for example,
addObserver:toObjectsAtIndexes:forKeyPath:options:context:).
mmalc
_______________________________________________
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