Forum Xamarin Xamarin.iOS

Detect Programatic Change of Text Field

JustinGoldenJustinGolden USMember
edited May 2015 in Xamarin.iOS

I need to detect a programatic change of a text field. The .valueChanged() only works when the end user changes the value. I need a way of calling a method when the value is changed by a method which I don't have access to. It appears that this might be possible with an observer, but I can't find any information regarding how to implement it for this.


Best Answer


  • JustinGoldenJustinGolden USMember
    edited May 2015

    Thanks Adam. For future reference in case anyone else has an issue, let me post how I was able to accomplish what I needed. Let's say you have a UITextField "myTextField".

    In the ViewDidLoad()method, one would put myTextField.AddObserver ("text", NSKeyValueObservingOptions.New, ObserveValue);

    The first parameter is the value which you with to observe. A list of properties for UITextField can be found here. The last parameter is the method you wish to call when a change has been observed.

    The method which you call must use the parameter Foundation.NSObservedChange so my method signature was public void ObserveValue(Foundation.NSObservedChange a) Hopefully this helps someone else out having a similar issues.

Sign In or Register to comment.