Cocoa: How to bind a boolean property to NSCellStateValue?

I would like to bind a boolean enabledproperty NSTextFieldto a state NSButton. I already tried adding a custom NSValueTransformerone that converts the state NSButtonto NSNumber. However, in this case, text fields are disabled for some reason. My second approach: the bad fails, as it NSValueTransformerdoes not offer return primitive types such as BOOL.

Example:
The screenshot shows an example in which text fields are disabled because the flag has a state NSOnState. I would also like to bind tags to this state.

Disabled text fields

In addition, it would be convenient if I could set the “disabled text” in Interface Builder . In the above example, I set the text in a related class.


Edit:

I set the self.anonymousLoginCheckbox.statemodel key path for the included property of the account text field. Similarly for the password text field. However, it does not work .

Interface Builder Binding


Update:

I created a project that is available on GitHub, demonstrating the implementation , kindly described by Nicholas Bachshmidt.

+5
source share
1 answer

NSButton KVO state. Cocoa , . NSButton state - cell state, -[NSButton setState:] ( KVO), , ( -[NSCell setState:] ). self.anonymousLoginCheckbox.cell.state, .

+13

All Articles