Searching around the Internet, I see a lot of questions and answers about how
to observe changes to properties of objects in a NSArrayController. Everything
I have seen, though, relates to a third object doing the observing. For
instance:
[arrayController addObserver: viewObject forKeyPath:
@"arrangedObjects.someProperty" ... ]
I am trying to do something similar, but I want to notify the array controller
itself.
I have an array controller that drives a table view, enables/disables an action
button, and updates check marks for menu items in the action button's drop down
menu. That all works fine.
When I select an action, I want to change a property and update all of the
array controller's bindings (update the table view to reflect the change,
update the drop down menu's check mark). For example, I have an "archive"
action that should update the item's cell in the table view to display the
"archived" graphic and "Archive" should be checked in the drop down menu.
I followed the Hillegass example of adding an observer whenever an item is
added to the array controller and removing the observer whenever an item is
removed from the array controller. So, I have...
- (void) startObserving: (id) object
{
[object addObserver: arrayController forKeyPath: @"someProperty" ... ];
}
- (void) stopObserving: (id) object
{
[object removeObserver: arrayController forKeyPath: @"someProperty" ... ];
}
The idea being that the array controller is notified whenever someProperty
changes. However, nothing happens when I change the property.
I used my window controller as the observer instead of the array controller,
added an observeValueForKeyPath:... method and verified that changing the
property of an object does, in fact, trigger an observeValueForKeyPath:... call.
So, two questions: 1) is it even the correct approach to have the array
controller observe changes in order to update bindings?, 2) if it is, is there
something I am missing?
_______________________________________________
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]