Bug 864

Summary: ValueChanged event is not fired for UITextField
Product: iOS Reporter: Adrian Grigore <adrian>
Component: Xamarin.iOS.dllAssignee: Bugzilla <bugzilla>
Severity: critical CC: flaviusdemian91, jiri.zoudun.dev, mono-bugs+monotouch, rolf
Priority: ---    
Version: 4.x   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Adrian Grigore 2011-09-16 15:31:32 UTC
The event "ValueChanged" is not fired on a UITextField when a charactor is
typed (or at all). 

(the Changed event IS fired in a UITextView, so I assume it's a typo?)

Steps to reproduce the problem:
1. Add a UITextField to a form. Wire it up
2. In MonoDevelop, attach to the field's ValueChanged event.
3. Put a breakpoint / logging in the valuechanged event code
4. watch it not fire the event as you type into the field

This bug seems identic to an old bug described at https://bugzilla.novell.com/show_bug.cgi?id=596930, but even though the bug is marked at RESOLVED, I was still able to reproduce it with version 4.0.7
Comment 1 Rolf Bjarne Kvinge [MSFT] 2011-09-21 07:48:58 UTC
The problem is that the native UITextField doesn't have (the native equivalent of) a Changed event, so there is nothing MonoTouch can hook up to.

There is however a notification you can observe (for the test project in the other bug report):

NSNotificationCenter.DefaultCenter.AddObserver (UITextField.TextFieldTextDidChangeNotification, (notification) =>
    Console.WriteLine ("Character received! {0}", notification.Object == TextField);

which will enable you to listen for when the text field's text changes.
Comment 2 Jiří Zoudun 2016-09-28 08:04:42 UTC
The cleanest way to observe UITextField changes is

_textField.AddTarget((sender, e) =>
    // Do your stuff in here
}, UIControlEvent.EditingChanged);

You don't have to subscribe to a system-wide notification center and you don't have to unregister observer when you're destroing a text field.
Comment 3 Flavius Demian 2016-10-26 18:58:36 UTC
The suggested fix with 

_textField.AddTarget((sender, e) =>
    // Do your stuff in here
}, does not work for me. 

Any other suggestions?