Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually setting "text" for a UITextField does not call .EditingChanged

I have subclassed UITextField which has the target

self.addTarget(self, action: "onChange:", forControlEvents: .EditingChanged)

This works fine when the user is typing in the textfield. Although I would need to the same method "onChange:" to be called when the textfield's "text" property is manually updated.

let tf = CustomTextField()
tf.text = "Trigger !!!"

How could I do this ?

like image 778
Prakash Raman Avatar asked Oct 22 '25 06:10

Prakash Raman


1 Answers

This is intentional, to prevent endless echo if you need to change the text programmatically in an event handler.

Use sendActions(for controlEvents:) to manually notify event handlers.

tf.text = "Trigger !!!"
tf.sendActions(for: .editingChanged)
like image 192
Léo Natan Avatar answered Oct 23 '25 21:10

Léo Natan