uitextview在点击并检测链接时成为第一响应者

时间:2012-06-10 21:23:12

标签: ios xcode4

我正在尝试创建一个检测链接的UITextView,并且当点击不在链接上时变为可编辑。

本机iphone笔记应用程序表现出这种行为,simplenote也是如此。

我在此处找到了最接近的解决方案:http://blog.stevex.net/2012/05/editable-uitextview-with-links/使用此代码:

// Add the tap gesture recogniser to the view.
- (void)configureTextView {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self    action:@selector(textViewTapped:)];
textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeLink;
[textView addGestureRecognizer:recognizer];
}

// Notification from the recogniser that the UITextView was tapped
- (void)textViewTapped:(UIGestureRecognizer *)recognizer {
UITextView *textView = (UITextView *)recognizer.view;
textView.editable = YES;
[textView becomeFirstResponder];
}

// UITextViewDelegate method
- (void)textViewDidEndEditing:(UITextView *)textView {
textView.editable = NO;
}

此解决方案的问题在于需要长按才能跟踪链接。

0 个答案:

没有答案