Search code examples
objective-cxcodensbuttonnsdatepicker

Enable/disable datepicker with checkbox


I am trying to enable and disable a datepicker with a checkbox, but I can not. What's wrong?

if ([checkBox state]==NSOnState) {
        [datePicker isEnabled];
    }

Solution

  • The -isEnabled method is asking if the date picker is enabled. It doesn't change anything. You use -setEnabled: to change the state. For example:

    [datePicker setEnabled:([checkBox state]==NSOnState)];