advice needed for NSArrayController's selection bindings
advice needed for NSArrayController's selection bindings
- Subject: advice needed for NSArrayController's selection bindings
- From: Paul Forgey <email@hidden>
- Date: Fri, 7 Apr 2006 18:13:46 -0700
Sorry to keep posting so many questions about this topic that I end
up answering myself a day later. I really do have an issue this time.
I've made a sample application to isolate the behavior I am seeing in
my real application. Take:
NSTreeController (treeController) containing an NSMutableArray of
NSMutableDictionary objects.
NSOutlineView, with a single column bound to
treeController.arrangedObjects.name.
NSTextField, bound to treeController.selection.name.
Set as the controller's contents a mutable array with one entry being
the root object, an NSMutableDictionary. It's children key contains
an NSMutableArray of three MSMutableDictionary objects.
Select the second child item, so the third item will be selected
after removing it.
If I programatically delete this selected item, using proper KVO
compliant mutable array methods, the tree controller updates
properly. The text edit field does not. It still contains the
contents of the now deleted object, and will until the tree view
becomes first responder again or the selection changes.
If I tell the tree controller to remove the selected item, things
work fine.
This is a problem because my application's data model can't
programatically remove items safely without going through the
controller. This blows the whole point of cocoa bindings, doesn't
it? It creates problems in my real application.
I've read the documentation section "Troubleshooting Cocoa Bindings"
where this type of situation is mentioned. I am mutating the child
objects with KVO compliant methods by using
mutableArrayValueForKey:@"children" on the parent object to remove
the child item. In fact I can see the the tree view not updating if
I access the array directly, which would be expected.
If I observe the key path @"selectedObjects" in my controller I do
get notified if the selected object is programatically deleted. Is
there any way to tell a binding to "update now" or something as a
workaround?
I don't want to have to go through the tree controller for deleting
my objects for many reasons:
- my document owns this model data, and the tree controller could be
one or none of any or many in any arbitrary window controller
- I would have to exhaustively search the hierarchy for the object
Is this a bug? How do I work around this?
_______________________________________________
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