Search code examples
objective-ccocoacocoa-bindingsnstextfield

NSTextField commitEditing to a binding


How does textShouldEndEditing for an NSTextField usually update coca bindings (by default)? I've overridden the method and, as a side-effect, bindings are no longer updating so I want to reinstate this behavior. The only advice I've seen is to create an additional NSObjectController and commitEditing to that but what code did the original textShouldEndEditing use?

In my situation, my NSTextField has its value bound to an NSController called Jobs. From my NSTextField subclass, I can see no way to reference Jobs to commitEditing. Jobs is present in Interface Builder as a result of creating an NSArrayController for a Jobs entity.


Solution

  • There were two answers for this that I could find:

    1. infoForBinding. I wasn't aware of this method and it can be used to identify the binding controller and target it.

    2. I had thought an IBOutlet couldn't be used with subClasses I wasn't initialising in IB but I forgot I could access the outlet from the dropped in subClassed NSTextFields in my application. It was then easy to create an IBOutlet to my NSArrayController and all worked as I hoped.