I have a text field that I am using to show a "total cost" computed from several other text fields. When I get controlDidEndEditing:
, I calculate this tota开发者_开发百科l cost and put it into the Total Cost field using setDoubleValue:
. I have the value of the Total Cost field bound to an array controller, and if I change the field's value manually, then it is saved into the controller's array. If I do it programmatically, though, then the field's display will change but the array and the value displayed in my table does not change.
What is the reason?
If you have a bound control, like a textField, changing it's state using a method like setStringValue: will not trigger the bindings mechanism to push the change out to the binding target. This is simply part of the design of bindings. If you want to effectively change the value of the textField programmatically, you need to change it in your model object using the setter for the key you have it bound to, or using setValue:forKey. So if you have nameTextField bound to person.name, you need to call [person setName:newName] or [person setValue:newName forKey:@"name"].
精彩评论