Re: Mixed-state checkboxes
Re: Mixed-state checkboxes
- Subject: Re: Mixed-state checkboxes
- From: Quincey Morris <email@hidden>
- Date: Fri, 08 Jul 2016 14:11:47 -0700
- Feedback-id: 167118m:167118agrif8a:167118shq7FCTSi2:SMTPCORP
On Jul 8, 2016, at 11:44 , Jonathan Taylor <email@hidden> wrote:
>
> I get an error: "this class is not key value coding-compliant for the key globalChannelEnableState"
It may well be that for the checkbox to be editable/actionable for the user, the underlying property must be settable. I think you could solve that by just providing a setter method that literally does nothing. However, this still leaves the issue of letting the binding (the UI end of the binding) know that the correct value is not the one it tried to set.
Either one of two things is true:
a. The binding, after setting a value, assumes that is the value.
b. The binding, after setting a value, gets the value again, and uses that instead of what it set, to update the UI.
If the answer is b, then you have nothing else to do. If the answer is a, as suggested by the fact that you’ve already gone to some trouble, then it’s harder.
In this case, rather than trying to trigger a later update as you have, I think an alternative would be to use the validate<Key> mechanism. That is, you write a method named “validateGlobalChannelEnableState:” (with some more parameters, you can look it up in the KVC documentation, or I think Xcode will autocomplete it for you if you start typing the method name at the top level of your .m file).
Such methods are intended to detect errors in user input, but they have the useful ability to return alternative (corrected) values that replace the user-entered value in the UI, without actually generating an error. Since bindings use KVC, they support validate<Key> automatically, and this may be the simplest way to restrict your user “input” to on and off.
A warning: validate<Key> is a bit awkward to use, because it doesn’t have any automatic translation between scalar and object values like other KVC accessors do. So, for a checkbox, remember that the incoming/outgoing values will be NSNumber objects with a BOOL value.
_______________________________________________
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