当文本视图可编辑时,iphone UITextView 不支持数据检测器

发布于 2024-08-18 14:28:04 字数 239 浏览 1 评论 0原文

我在构建时收到一个有趣的警告(iPhone模拟器),给出以下内容:

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

这在谷歌上基本上不存在,我想删除它。

我的 editview.xib 有一个文本视图,我可以在其中写入注释。还需要更多信息吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我不咬妳我踢妳 2024-08-25 14:28:05

我有四个不同的 Xib,它们具有相似的 TextView,也用于注释。我也收到了同样的警告。禁用“检测电话号码”“检测链接”的建议确实删除了警告。但是,我希望我的用户仍然能够在我的笔记中使用检测器。

这就是我在应用程序中解决问题的方法:

  1. 在 IB 中:我取消选择 TextView 的两个属性。 -(这确实会停止构建警告)。

  2. 在我的 - (void)viewDidLoad { 中,我将 textView 的属性设置为以下内容:
    myTextView.dataDetectorTypes = UIDataDetectorTypeAll; 启用所有类型的数据检测器(电话号码和 URL 地址)。

  3. 在我的视图控制器中:-(void)textViewDidBeginEditing:(UITextView *)sender {
    方法中,我使用以下方法将数据检测器重新关闭myTextView.dataDetectorTypes = UIDataDetectorTypeNone

  4. 然后利用 -(void)textViewDidEndEditing:(UITextView * )发件人{
    方法,我使用: myTextView.dataDetectorTypes = UIDataDetectorTypeAll;

    将它们重新打开ON

当用户编辑 UITextView 并转动数据时,此方法会禁用数据检测器当用户完成编辑时,探测器重新打开。此修复程序允许从 textView 中选择电话号码和 URL,这样我就不会失去该功能。


我在 UITextView 的 DataDetectors 的 Apple 文档中发现了以下内容:在使用 UITextView 一段时间后,希望它有所帮助。

UIDataDetectorTypes:

定义可以在基于文本的内容中检测到的信息类型。

类型:

  • UIDataDetectorTypePhoneNumber;
  • UIDataDetectorTypeLink;
  • UIDataDetectorType无;
  • UIDataDetectorTypeAll;

Update: 11-5-2010;

额外说明:
如果 UITextView 为“可编辑”,则不允许使用数据检测器,因为将有太多变量来跟踪用户对文本的更改以及尝试执行电话呼叫或链接的触摸。

解决方案:
使用 self.textView.editable = NO; 加载 TextView,并根据我上面列出的类型设置 UIDataDetector。这样,如果用户想要“选择”网址或电话号码等,代理就可以处理。当您需要用户编辑textView时,请打开self.textView.editing = YES; &相应地删除您的 UIDataDetectors。这应该确保编译期间不会出现错误或警告。

特别考虑:
重新启用时,请务必首先删除数据检测器,然后启用“editing = YES;”...如果仍然分配了 UIdata detectors,则启用编辑的顺序很重要。

因此,序列顺序应该是这样的...

  • 编辑 textView: 1. 删除数据检测器,2. 然后启用编辑 = YES。

  • 使用 DataDetectors: 1. 禁用编辑 = 否; 2. 然后添加数据检测器。

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.

楠木可依 2024-08-25 14:28:05

我也看到了这个警告。以下是我修复该问题的方法:

在 Interface Builder 的 xib 文件中,选择文本视图,然后调出属性检查器。确保“检测电话号码”和“检测链接”均未选中。

我检查了“检测链接”,结果发现这就是导致警告的原因。基本上,如果文本视图是可编辑的,您不希望打开这些自动检测功能。

I was seeing this warning as well. Here's how I fixed it:

In the xib file in Interface Builder, select your text view, and bring up the attributes inspector. Make sure that "Detects Phone numbers" and "Detects Links" are both UNCHECKED.

I had "Detects Links" checked, and turns out that's what was causing the warning. Basically, if the textview is editable, you don't want these auto-detect features turned on.

寂寞笑我太脆弱 2024-08-25 14:28:05

罗嗦了!

textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeAll;

URL地址必须以“http://”开头,否则textview无法检测到。

So Wordy!

textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeAll;

the URL address must start with "http://", otherwise the textview cannot detect it.

羁〃客ぐ 2024-08-25 14:28:05

我考虑尝试使用“delaysTouchesBegan = YES”和“cancelsTouchesInView = NO”的 Tap-Gesture-Recognizer

它仍然很容易解决!

加载禁用可编辑以及 UIDataDetectorTypeAll 或您要检测的链接类型的视图。然后添加一个 GestureRecognizer:

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(editTextRecognizerTabbed:)];
recognizer.delegate = self;
recognizer.numberOfTapsRequired = 1;
[self.textViewNotes addGestureRecognizer:recognizer];

这样您就可以在此方法中更改设置:

- (void) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer;
{
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeNone;
    self.textViewNotes.editable = YES;
    [self.textViewNotes becomeFirstResponder];
}

并且至少您必须在用户完成文本输入后将编辑和检测设置更改回来:

- (void)textViewDidEndEditing:(UITextView *)textView;
{
    self.textViewNotes.editable = YES;
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeAll;
}

就像魅力一样!

I thought about trying to use a Tap-Gesture-Recognizer with "delaysTouchesBegan = YES" and "cancelsTouchesInView = NO"

It is still quite easy to solve!

Load view with editable disabled as well as UIDataDetectorTypeAll or the types of links you want to detect. Then add a GestureRecognizer:

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                             action:@selector(editTextRecognizerTabbed:)];
recognizer.delegate = self;
recognizer.numberOfTapsRequired = 1;
[self.textViewNotes addGestureRecognizer:recognizer];

So you can change settings within this method:

- (void) editTextRecognizerTabbed:(UITapGestureRecognizer *) aRecognizer;
{
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeNone;
    self.textViewNotes.editable = YES;
    [self.textViewNotes becomeFirstResponder];
}

And at least you have to change the edit and detections settings back after user has finished the text input:

- (void)textViewDidEndEditing:(UITextView *)textView;
{
    self.textViewNotes.editable = YES;
    self.textViewNotes.dataDetectorTypes = UIDataDetectorTypeAll;
}

works lika a charm!

咆哮 2024-08-25 14:28:05

UITextView 的数据检测器将用于复制和粘贴。由于您将其设置为可编辑,因此在您认为应该粘贴但不应该复制的地方不应允许复制/粘贴。

Data detectors for the UITextView would be for copy and paste. Since you are setting it as editable, copy/paste shouldn't be allowed where you think paste should, but copy shouldn't.

青巷忧颜 2024-08-25 14:28:05

Simplenote 在 iOS 4 上以某种方式执行此操作。(如果您想尝试,有一个免费/精简版。)

它的行为有点不同:
当点击突出显示的部分之一时,它仍然会开始编辑,并且不会点击链接。

但是,当您点击并按住检测到的数据类型时,它会向您显示用于呼叫、打开链接或其他任何内容的菜单。

此外,当点击文本内部时,编辑实际上从您点击的位置开始。
因此,他们以某种方式删除了 dataDetectors,启用编辑并在识别点击后将触摸转发到可编辑的 UITextview。

有什么想法如何做到这一点吗?

我考虑尝试使用带有“delaysTouchesBegan = YES”和“cancelsTouchesInView = NO”的Tap-Gesture-Recognizer,

这样我可以删除dataConnectorTypes并将其设置为可编辑的识别器的操作方法,
希望 UITextview 的触摸能够在此之后交付。

但目前还没有时间测试。

Simplenote somehow does this on iOS 4. (There's a free/lite version in case you wanna try.)

It acts a little bit different:
When tapping on one of the highlighted parts, it still starts the editing, and won't follow the link.

But when you tap-and-hold on a detected dataTpye, it shows yout the menu for calling, open the link or whatever.

Also, when tapping inside the text the editing really starts at the place you tapped.
So they somehow remove the dataDectectors, enable editing AND get the touches forwarded to the editable UITextview AFTER the tap is recognized.

Any ideas how to do that?

I thought about trying to use a Tap-Gesture-Recognizer with "delaysTouchesBegan = YES" and "cancelsTouchesInView = NO"

So I can remove the dataConnectorTypes and set it editable on the action method of the recognizer,
and hopefully the touches to the UITextview are delivered AFTER that.

But haven't had time to test it so far.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文