views:

128

answers:

1

Hello,

Does anyone know how to prevent Cocoa binding to set values back to the bound property but still fires the default action selector?

I am trying to bind a NSTextField to a readonly NSString property on my data object. My data Object is like

...

@property(readonly) NSString* outCome;

-(void)otherMethodsAffectOutCome;

...

I bound the NSTextField with the outcome property and in default action handler I called -otherMethodAffectOutCome, and I hope will/didChangeValueForKey to fire outCome property's observer and back the NSTextField.

But it doesn't work, NSTextField will crash because it tries to set changed text back via setOutCome method... I think I need NSTextField watch the property value changes, but don't try to set values back on text change, How should I do that?

Thanks! -Jonny

A: 

I came up with a workaround finally by overriding the setValue:forUndefinedKey: method on my data object. if the key name is outCome, just return without calling super.

Jonny

related questions