Reputation: 999
I've having an issue receiving up the actions from an NSTextField. In my app, I have some NSTextFields created via interface builder, while others are created programmatically.
It appears that by default, the IB textfields send an action on end editing. But if I create a NSTextField by using the init(frame:)
initializer, it only sends an action on enter.
I realize I can "solve" this by subclassing and overriding the controlTextDidEndEditing
function and then sending an action there, but when I call super.controlTextDidEndEditing
it also sends an action. So the action is then sent twice... I really just want my text fields created via code to use the option "Sent on end editing".
Is there not a way to change this interface builder setting via code?
Upvotes: 6
Views: 1054
Reputation: 385930
You can set it in code. It is actually a property on the text field's cell:
// Same as IB's “Sent On End Editing”.
myTextField.cell?.sendsActionOnEndEditing = true
// Same as IB's “Send on Enter Only”.
myTextField.cell?.sendsActionOnEndEditing = false
Upvotes: 7