iphone UITextView does not support data detectors when the text view is editable

oberbaum picture oberbaum · Jan 19, 2010 · Viewed 12.3k times · Source

I am getting an interesting warning at build time (iPhone simulator) that gives the following:

EditView.xib:35:0 UITextView does not support data detectors when the text view is editable.

This is basically non existent on google and I would like to remove it.

My editview.xib has a textview where I write notes into it. Is there any more info that is needed?

Answer

Newbyman picture Newbyman · Feb 28, 2010

I have four different Xibs with similar TextViews that are used for notes as well. I was getting the same warnings. The suggestion to disable the "Detects Phone Numbers" and "Detects Links" does removes the warnings. However, I wanted my users to still have the ability to use the detectors in my notes.

This is how I solved the issue in my app:

  1. In IB: I deselected the two properties for the TextView. -(which does stop the build warnings).

  2. In my - (void)viewDidLoad { I set the properties of the textView to the following: myTextView.dataDetectorTypes = UIDataDetectorTypeAll; which enables the data detectors of all types (phone numbers and url addresses).

  3. In my View Controller's: -(void)textViewDidBeginEditing:(UITextView *)sender { method, I turned the data detectors back OFF using: myTextView.dataDetectorTypes = UIDataDetectorTypeNone

  4. Then taking advantage of the -(void)textViewDidEndEditing:(UITextView *)sender { method, I turned them back ON using: myTextView.dataDetectorTypes = UIDataDetectorTypeAll;

This method disables the data detectors when the user is editing the UITextView and turns the data detectors back ON when the user is finished editing. This Fix allowed for selection of the phone numbers and URL from within the textView, so that I did not loose the function.


I found the following in the Apple Docs on the DataDetectors for UITextView: after playing around with the UITextView for a while, hope it helps.

UIDataDetectorTypes:

Defines the types of information that can be detected in text-based content.

Types:

  • UIDataDetectorTypePhoneNumber;
  • UIDataDetectorTypeLink;
  • UIDataDetectorTypeNone;
  • UIDataDetectorTypeAll;


Update: 11-5-2010;

Extra Note: Data detectors are not permitted if UITextView is "Editable", because there would be too many variables to track users changes to text as well as touches with trying to execute phone call or links.

Solution: Load the TextView with self.textView.editable = NO; and set you UIDataDetector's based on the types I listed above. This way if the user wants to "select" web address or phone number etc, the delegate can handle. When you need your user to edit the textView, then turn ON the self.textView.editing = YES; & remove your UIDataDetectors accordingly. This should assure no errors or warnings during compiling.

Special Consideration: Be sure to first remove the datadectors when re-enabling, then enable "editing = YES;"...The order is important no to enable editing if UIdatadetectors are still assigned.

Therefore, the sequence order should be something like this...

  • To Edit textView: 1. remove data detectors, 2. then enable editing = YES.

  • To Use DataDetectors: 1. Disable Editing = NO; 2. then add data detectors.