无法在UITextView中进行URL可点击 [英] Can't make URL clickable in UITextView

查看:143
本文介绍了无法在UITextView中进行URL可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Interface Builder来布局我的应用。我有一个包含一些文本的UITextView,其中一部分是我想点击的URL(例如启动浏览器)。我已经阅读了如何执行此操作并相信我正确地执行此操作,但是当URL显示为蓝色/可点击时,在iPhone模拟器中单击它不起作用。什么都没发生。

I'm using Interface Builder to layout my app. I have a UITextView that contains some text, part of which is a URL that I'd like to make clickable (e.g. launches a browser). I've read up on how to do this and believe I'm doing it correctly, however while the URL appears blue/clickable, clicking it in the iPhone emulator doesn't work. Nothing happens.

我的控制器:

@interface FirstViewController : UIViewController <UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UITextView *review;
@end

在我的实施中,我 @synthesize review; (并且能够操纵视图的文本,所以不要认为这是问题)。

In my implementation I @synthesize review; (and am able to manipulate the view's text, so don't think that's the issue).

在IB中我有:

..然后我去设置文本(并尝试在视图中点击可点击的URL)我这样做:

..then later when I go to set the text (and attempt to make URLs in the view clickable) I do:

self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.dataDetectorTypes = UIDataDetectorTypeLink;

...显示如下内容:

...which displays something like:

...这真的看起来它想要工作,但是当点击URL没有任何反应。我错过了什么?

...which really looks like it wants to work, however when clicking the URL nothing happens. What am I missing?

- 更新 -

尝试添加 self.review.editable = NO; 以回应Dixit Patel的回答,但它没有解决问题:

Tried adding self.review.editable = NO; in response to Dixit Patel's answer, but it didn't fix the issue:

self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.editable = NO; 
self.review.dataDetectorTypes = UIDataDetectorTypeLink;


推荐答案

问题在于用户未在IB的属性检查器的视图部分底部检查已启用交互

这篇关于无法在UITextView中进行URL可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆