Re: bindings via file's owner don't update
Re: bindings via file's owner don't update
- Subject: Re: bindings via file's owner don't update
- From: James Bucanek <email@hidden>
- Date: Mon, 29 Nov 2010 08:37:04 -0700
Mikkel Eide Eriksen <mailto:email@hidden> wrote
(Monday, November 29, 2010 6:00 AM +0100):
When reading a file, my Document object tells LoadingWindowController to show
its window & [loadingWindowController setDocument:self];
I'm not sure this is your problem (and I'm sure someone will
correct me if I've wrong), but I'd had issues with KVO when
replacing object properties. This would also affect bindings,
since bindings is based on KVO.
Basically, if I add an observer using the path
"document.someProperty", KVO attaches the observer to the the
someProperty object, not document. So if I change it
(document.someProperty = newProperty), newProperty replaces the
original object, which is then released. newProprety doesn't
have any observers and doesn't post any notifications when its
properties change.
I don't have a general solution, but in the one really ugly
situation where I had to deal with this I ended up overriding
setSomeProperty so that it first removes all of the KVO
observers from the object that it's discarding and reestablishes
them on the one being set.
A simpler solution might be to create a "proxy" accessor in your
controller object. Create a -(NSInteger)documentObjectCount {
return document.objectCount; } property method in
LoadingWindowController and bind to that. Now, no matter how
many times the document object is changed, the binding to
loadingWindowController.documentObjectCount remains intact.
Note, however, for this to work you'll have to update the load
count via the controller (controller.documentObjectCount++), or
the controller will have to observe the objectCount property of
the current document to fire the appropriate manual KVO
notifications. A slightly simpler solution would be to not have
objectCount a property of document, but simply have the document
fire an NSNotification as objects are loaded and have
LoadingWindowController observe those notifications (and use
those to fire the manual KVO notifications, or simply store the
updated value in a KVO compliant property of the controller).
I really love KVO and bindings, but managing it in a changing
object landscape can get a little harry.
Good luck,
James
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden