On Jul 8, 2016, at 11:44 , Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to