On Oct 5, 2009, at 10:52, David Hirsch wrote:

This seems to be precisely the solution. The problem was that the bound object didn't know about changes to the array. There are two ways to inform it: manipulate the array through the controller, or fire my own KVO. In fact, here is the latter solution in the Apple docs:http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/ Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#//apple_ref/ doc/uid/20001844 (listing 3).

Or are you suggesting that I should be notifying using some other key?

I'm suggesting that you have a data model (an array property of your document), a mediating controller (the NSArrayController) that has a derived property (arrangedObjects, derived from the data model), a user interface object (the NSTableView), and, incidentally a coordinating controller (the NSDocument subclass, or its NSWindowController).

The problem isn't in "arrangedObjects". The problem is that your data model isn't (apparently) being updated KVO compliantly:

- (id) init... {
...
        myArrayIvar = [NSMutableArray array];
...
}

- (void) awakeFromNib {
...
        [myArrayIvar addObject: someObject]; // oops, not KVO compliant
...
}

If that's what's going wrong, then the solution is, most directly:

- (void) awakeFromNib {
...
[[self mutableArrayValueForKey: @"myArrayPropertyName"] addObject: someObject]; // KVO compliance FTW
...
}

Or, indirectly:

- (void) awakeFromNib {
...
        [myArrayController addObject: someObject];
...
}

(because the behavior of the latter is to add the object KVO compliantly to the data model array on your behalf)

Which solution you chose depends on other factors (for example, the second one requires that your document subclass have an outlet to the array controller, which as a design choice has its own set of considerations).

Usually, if you find yourself using willChange/didChange, then something has gone wrong and you've leaped into hackland -- though, to be sure, there are non-controversial situations where using them is a viable choice.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to