KVO on array values -- member edit can't trigger?
KVO on array values -- member edit can't trigger?
- Subject: KVO on array values -- member edit can't trigger?
- From: Fritz Anderson <email@hidden>
- Date: Fri, 25 Jun 2004 15:13:33 -0500
Imagine a model object called StringCat. It has two keys:
parts a mutable array of objects with string values (objects that
respond to stringValue)
catenation a computed value, the concatenation of the string values.
In StringCat's +initialize method, one says that a change to "parts"
triggers a change to "catenation".
Create an ObjectController with a StringCat as content, and an
ArrayController with the StringCat's parts array as its array content.
Bind an NSTextField to ObjectController.selection.catenation, and a
column of an NSTableView to
ArrayController.arrangedObjects.stringValue. Add an NSButton for adding
elements through ArrayController.
Use the button to add an element to the StringCat, and use the table to
edit the element.
Notice that the text field does not change, even when you stop the edit
with the return key. It will not change until the next time you press
the add button -- then it will reflect the contents of all the
elements, except the one just edited.
What I gather from this is that there is no way to tell the KVO
mechanism that the _content_ of an array member has changed. There
seems to be no way to express from-many value dependencies like
concatenations. I'd have thought the change would trigger a
NSKeyValueChangeSetting notice, but maybe I'm expecting too much.
The scenario I give is common enough that I am sure I must be missing
something. Is the solution simply that StringCat has to observe each of
its members manually?
-- F
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.