Re: Mixed-state checkboxes
Re: Mixed-state checkboxes
- Subject: Re: Mixed-state checkboxes
- From: Quincey Morris <email@hidden>
- Date: Fri, 08 Jul 2016 10:35:45 -0700
- Feedback-id: 167118m:167118agrif8a:167118shq7FCTSi2:SMTPCORP
On Jul 8, 2016, at 05:36 , Jonathan Taylor <email@hidden> wrote:
>
> My setter code currently looks like this:
>
> -(void)setGlobalChannelEnableState:(NSInteger)state
In the circumstances you describe, a setter method is effectively an action method, not a setter — that is, it becomes a method that’s called when your code needs to do something, rather than a way to set some state. As you’ve found, the real setter method tends to work against you here, because you have to figure out what the binding expects with the changed value it thinks it’s setting.
So, I think a cleaner approach is to leave out the setter method entirely, and use a real action method instead. With no setter, the binding won’t try to update the property, it’ll basically be read-only. When the checkbox is clicked, the action method is still invoked — it’s a NSButton, after all. All the action method has to do is retrieve the current global state via the getter, then set the individual states needed to flip it, sandwiched between one pair of will/didChange calls for the key “globalChannelEnableState”.
You don’t need to dispatch anything to a later iteration of the main event loop. (Even in your current code — the setter will automatically generate the KVO notification, so doing it again later is redundant.)
_______________________________________________
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