On Oct 5, 2009, at 1:13 PM, David Hirsch <[email protected]> wrote:

Thanks, Volker.  rearrangeObjects did work, but I don't understand why
that call should be necessary.  If anybody out there wants to educate
me, I'd appreciate it.

(More info: I have my ArrayController in IB bound to an array (phases)
of File's Owner (which is my NSDocument subclass).  In the document's
init method, I make phases an empty NSMutableArray, and in the
document's windowControllerDidLoadNib method, I populate that array
with data.)

Dave,

An NSMutableArray is not KVO compliant for addition and deletion of entries. You must either provide manual notification or create a class with a To-Many property that is KVO compliant.

From the "Key Value Observing Programming Guide" --

Automatic notification is also supported for the collection proxy objects returned by mutableArrayValueForKey: and mutableSetValueForKey: . This works for to-many relationships that support the indexed accessor methods insertObject:in<Key>AtIndex:,replaceObjectIn<Key>AtIndex:, and removeObjectFrom<Key>AtIndex:.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#/ /apple_ref/doc/uid/20001844


To implement a KVO compliant class for a To-Many property, read more about "Collection Accessor Patterns for To-Many Properties" in the "Key Value Coding Programming Guide"

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html

Which says:

"For manipulating the contents of the collection it is best practice to implement the additional accessor methods referred to as the collection accessor methods."

To do so, you must provide a minimal complement of indexed accessors (you may certainly use an NSMutableArray as a backing store).

HTH,
--Stuart



-Dave

On Oct 5, 2009, at 9:40 AM, Volker in Lists wrote:

Hi,

without knowing how you add objects to the ArrayController - and
when, and without knowing what and how is bound exactly - guessing
is most that can be done.

It seems the bindings are okay from the beginning, but the changes
to the ArrayControllers content are only observed when the sortOrder
is changed. Maybe you need only a single [NSArrayController
rearrangeObjects] call or similar.

Volker

Am 05.10.2009 um 18:32 schrieb David Hirsch:

My window has two NSTableViews.  Each has two columns, each of
which is bound to a field in Phases, an NSArrayController.

When my window is displayed, I calculate my model, and the
NSTableViews show the headers, but blank data cells.  However, when
I click the header of one table, all four columns get populated
with data.  As far as I can tell (I've set breakpoints), this
happens without calling any of my code.  Note that this only works
if I click a text-based column.  If I click the column with image
cells, I get no response, so presumably the TableView is trying to
sort the data on the click, and somehow straightens out the
previously mucked-up binding at that time.

I'm posting here without code to see if anybody has experienced
this before.  It will be a major undertaking to reduce this problem
to a post-able amount of code.

I've tried making Phases (the NSArrayController) the data source
and delegate in addition to the column bindings, without solving
the problem.  I've tried adding another NSTableView and binding it
to other columns to see if I had done it wrong the first time.
That did not help.  The fact that the bindings do work after the
click seems to suggest that the binding setup is okay.

Thanks in advance,
Dave

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to