Colin
Colin

Reputation: 2099

Enabled binding for NSTextField bound to NSString

@interface MyClass {
  NSString *_myString;
}
@property (copy) *myString;
@end

@implementation MyClass
@synthesize myString = _myString;

- (void)awakeFromNib {
  self.myString = @"";
}

In the nib, I have an NSTextField and an NSButton. The text field's Value binding is set to myClass.myString. I verified that the variable _myString is being updated correctly when text is typed into the text field.

The Enabled binding of the NSButton is set to myClass.myString.length. However, when I start up the program, the NSButton is enabled! If I go to the textfield and type something into it, the button stays enabled. Then if I erase the text from the textfield, the button becomes disabled.

But why isn't the button disabled to begin with, after the call in awakeFromNib ? Do I have to do some additional work to make the binding work in the opposite direction (myClass.myString --> NSTextField) ? I thought that declaring myString as a property would do the trick.

Upvotes: 0

Views: 397

Answers (1)

Keith Smiley
Keith Smiley

Reputation: 63914

I'm not sure what is causing this but I would say the easiest way to fix it, since your text will start out empty, is in awakeFromNib do something like [myButton setEnabled:false];

Upvotes: 0

Related Questions