Search code examples
cocoa-bindings

Binding objects to a checkbox


Really simple binding question. I have a checkbox on my MainMenu.xib, and I also have a text field and a date picker. I want to bind the hidden attribute of the field/picker to the checkbox such that if the box is checked the date picker is not hidden, and the text field is hidden.


Solution

  • You'll want to do the following:

    Checkbox -> Bind Value to your boolean.

    Text Field -> Bind Hidden to same boolean.

    Date Picker -> Bind Hidden to same boolean. Set its Value Transformer to NSNegateBoolean.

    Here's a github project you can checkout for an example (everything is in the xib). https://github.com/macandyp/CocoaCheckBoxBindings