Re: Combing Bindings with Target-Action
Re: Combing Bindings with Target-Action
- Subject: Re: Combing Bindings with Target-Action
- From: Jeff Hutchison <email@hidden>
- Date: Thu, 16 Apr 2009 10:01:03 -0400
Thanks for the responses. I had used KVO on the bound property on an
earlier version and was encountering a small problem due to the nature
of my application. There might be cleaner way so some more details
might be helpful.
I'm writing an application that connects to my home theater receiver
on its telnet port to remote control and monitor it. The model
represents the state of the receiver and can be updated in three ways:
1. Through bindings to the application UI controls.
2. From events sent by the receiver as a response to commands sent by my app.
3. From events sent by the receiver due to other interactions with the
receiver (IR remote, front panel, embedded web server).
Two and three appear identical to my app but I can figure out case 2
by using the event handler's change dictionary's
NSKeyValueChangeOldKey and NSKeyValueChangeNewKey values.
I need to know if the model was updated by the UI or by networking
code so that I only send command to the receiver in response to UI
changes, not other interactions with the receiver. For example, the
problem is the observer would see the model "mute" value change to
"on" when I changed it at the receiver and interprets that as a change
on the app UI. It would then send a redundant "mute on" command to
the receiver.
Using target-action with bindings solved the problem nicely with a
minimum of extra code. If I fail to verify that a race condition
doesn't exist I can fall back to reading the values from the action's
sender parameter instead of the bound model.
Jeff
On Wed, Apr 15, 2009 at 11:26 PM, Kyle Sluder <email@hidden> wrote:
> On Wed, Apr 15, 2009 at 3:04 PM, Jeff Hutchison
> <email@hidden> wrote:
>> I am relying on the binding messages to complete before the
>> target-action message - is this an OK idea?
>
> Why not just register as an observer of the bound property?
>
> --Kyle Sluder
>
_______________________________________________
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