Search code examples
macoscocoacocoa-bindingsnstextfield

Setting editable on a NSTextField doesn't have any effect


I have an NSTextField in a view that is bound to a value in the view's view controller. When a button is pressed I wish to make the text field no longer editable so I use the following code:

- (IBAction)makeTextFieldNotEditable:(id)sender {
    self.textField.editable = NO;
}

Everything is bound correctly and I can confirm that the above method gets called when I press the button but the text field is still editable. How can I fix this?


Solution

  • This was because by default when you bind the value of an NSTextField in Interface Builder it ticks the box Conditionally Sets Editable meaning that the value the text field is bound to sets the editable property of the text field.

    Unticking this box made my original code work.