Re: Custom binding problem...can't figure out how to trigger a notification on set
Re: Custom binding problem...can't figure out how to trigger a notification on set
- Subject: Re: Custom binding problem...can't figure out how to trigger a notification on set
- From: mmalc crawford <email@hidden>
- Date: Wed, 4 Oct 2006 15:08:41 -0700
On Oct 3, 2006, at 2:46 PM, E. Wing wrote:
Thanks. This got me just about there. (Turns out I needed to save the
keypath too and call setValue:forKeyPath). I'm wondering what the best
strategy is for avoiding infinite recursion is. When I call
setValueForKeyPath inside my setter, it triggers another set
notification which causes the setter to be called again (and again).
This is illustrated in the Joystick example:
<http://developer.apple.com/samplecode/BindingsJoystick/>
and discussed in general terms in:
<http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html
>
If a user interacts with a bound view, the view updates the object to
which it is bound using KVC (in the example, in updateForMouseEvent:).
If the model object is updated, it informs the view "indirectly" using
KVO. In its 'observeValueForKeyPath:...' method, the view updates
itself but does *not* update the object to which it is bound (the
view's setter methods should not update the object to which is it
bound (in the example, see setAngle: and setOffset:, contrast with
observeValueForKeyPath:...).
Thus although there may be one update refresh cycle, it should not
cause an infinite loop.
mmalc
_______________________________________________
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