Bug 8028 - UITextView does not raise Changed even in iOS6
Summary: UITextView does not raise Changed even in iOS6
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.1.x
Hardware: Other Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-10-26 16:36 UTC by Sergey
Modified: 2012-11-05 10:35 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Sergey 2012-10-26 16:36:51 UTC
environment: iOS6

The "Chaned" event is not raised if change text thru Text property 

var textView = new UITextView();
textView.Changed += OnTextViewChanged;
text.Text = "";

but works properly if text is changed thru keyboard.

Please note: "Changed" event works fine in iOS5 on the same monotouch
Comment 1 Sergey 2012-10-26 17:03:49 UTC
Note: NSNotificationCenter.DefaultCenter.AddObserver(UITextView.TextDidChangeNotification, OnTextChanged, textView); works fine if change UITextView text thru Text property
Comment 2 Chris Hardy [MSFT] 2012-11-05 06:54:15 UTC
I took the following Objective-C article on UITextView (http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_uitextview_uitextviewdelegate_2/) and modified it so that you can press a button to set the TextView text and hooked up a AddObserver method.

On both iOS 5 and iOS 6 in Obj-C, the Changed event only fires when using the keyboard and not through setting the text programmatically, the project example can be found here: https://www.dropbox.com/s/1zvb8jrle7eocqi/TextViewObjC.zip

So whilst I can reproduce the issue on iOS 6, it looks as this is the correct behaviour and the AddObserver method is incorrect for both iOS 5 and iOS 6 with MonoTouch and the Changed event is causing the incorrect behaviour for just iOS 5.

Any thoughts Sebastien?
Comment 3 Sebastien Pouliot 2012-11-05 09:04:24 UTC
> Please note: "Changed" event works fine in iOS5 on the same monotouch

Sergey, please include the version numbers of the product you're using (it's not 6.1 since this version is not yet released).

You can get them from "MonoDevelop" menu, "About MonoDevelop" item, "Version Info" tab and copy/paste the version informations (at least down to the "Loaded assemblies" section).


The event should NOT occur if the text is changed from some code. From Apple documentation [1]:

> The text view calls this method in response to user-initiated changes to the text. 
> This method is not called in response to programmatically initiated changes.

[1] http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html

OTOH Apple documentation for UITextFieldTextDidChangeNotification [2] does not make such claims:

> Notifies observers that the text in a text field changed. 
> The affected text field is stored in the object parameter of the notification.

[2] http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html


There's no "custom" code inside the bindings for this type/event - so MonoTouch should behave identically to iOS/ObjC in both cases (delegate/event and observer). I'll try this on an iOS 5 device (with and without MonoTouch).


Chris: please always attach your test cases to the bug report (useful for regression tracking in the future).
Comment 4 Sebastien Pouliot 2012-11-05 10:04:56 UTC
> On both iOS 5 and iOS 6 in Obj-C, the Changed event only fires when using the
> keyboard and not through setting the text programmatically

Chris, that's not what I see (using your ObjC sample). On iOS 5.1 I get:

2012-11-05 09:53:35.636 TextViewARC[10079:707] Button Pressed!
2012-11-05 09:53:35.649 TextViewARC[10079:707] textViewDidChange:
2012-11-05 09:53:35.653 TextViewARC[10079:707] Any method called

if I click the button *when* the keyboard is visible. If the keyboard is *not* visible then I only get:

2012-11-05 09:54:01.396 TextViewARC[10079:707] Button Pressed!

On iOS6, with keyboard visible I get:

2012-11-05 10:00:06.504 TextViewARC[604:907] Button Pressed!
2012-11-05 10:00:06.514 TextViewARC[604:907] Any method called

and without the keyboard:

2012-11-05 10:00:42.168 TextViewARC[604:907] Button Pressed!

So yes there's a "bug/feature" here, but it's in iOS 5 (fixed) or 6 (new) - depending on how Apple interpret the "right" behaviour. You might want to fill a bug report on Apple's radar.
Comment 5 Sergey 2012-11-05 10:35:44 UTC

Sorry, my fault. Monotouch version is 6.0.4