OS X bindings: UI element isn't committing binding. Why is that?

128 Views Asked by At

Look at the simple app screenshot below. There is a text field and a segmented control. There are three bindings in play:

  • textfield value binding goes to NSUserDefaultsController values.TextValue
  • textfield alignment binding goes NSUserDefaultsController values.Alignment
  • segmented control selectedIndex binding goes to NSUserDefaultsController values.Alignment

So the segmented control controls the text field's alignment.

Problem: When the text field has first responder, if you click on the segmented control to change the alignment, the text field 1.) throws out the value being edited and reverts to the last bound value, 2.) does not update its alignment, 3.) remains first responder.

Expected behavior would be: when you change the segmented control value the text field resigns first responder, commits the value in the UI to user defaults, and updates its alignment. How can this be done?

enter image description here

1

There are 1 best solutions below

0
On

You’ve hit a bug and should report a RADAR. There have been many bugs with textfields and bindings when you’re editing a textfield, it’s not an area the engineers focused on originally.

You don’t even need to bind the textField’s value to replicate this, you can just bind the alignment of the textField.