1

I want to detect changing values in UITextField. So I added this target to my text field.

[field addTarget:metrixUIViewControllerIn action:@selector(executeScriptOnTextFieldChange:) forControlEvents:UIControlEventEditingChanged];

But the problem is, this executeScriptOnTextFieldChange: doesn't fire when I set the text programmatically. How to make it fire in both cases (user type the text and when programmatically set the text).

Randi
  • 639
  • 2
  • 6
  • 23
  • The event is to tell you when the text is changed by the user. If you change the text programmatically, then you already know it has changed. So no, the event can't be fired when you set the text yourself. – rmaddy Dec 14 '17 at 03:18
  • @rmaddy Any event that fire when programmatically set the text? – Randi Dec 14 '17 at 03:33
  • 1
    No and there is no need for any event. You already know it has been set since you just set it yourself. Read the duplicate I linked. – rmaddy Dec 14 '17 at 03:42
  • @rmaddy If its not in textfield is it possible with UITextView? – Randi Dec 14 '17 at 04:40
  • No. No controls send an event when you change it via code. You don't the event to fire. Simply call the same code if needed. – rmaddy Dec 14 '17 at 04:42
  • @rmaddy but in UITextField fires when we use [textfield insertText:@"my text"] according to the answer you suggested. – Randi Dec 14 '17 at 04:44

0 Answers0