我正在使用Interface Builder来布局我的应用程序。我有一个UITextView包含一些文本,其中的一部分是URL,我希望它可以点击(例如启动浏览器)。我已经阅读了如何实现这一点的相关资料,并且相信我做得正确,然而在iPhone模拟器中单击蓝色可点击的URL时没有反应。
我的控制器:
@interface FirstViewController : UIViewController <UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UITextView *review;
@end
在我的实现中,我使用@synthesize review;
(并且能够操作视图的文本,因此不认为这是问题)。
在IB中,我有:
然后稍后当我去设置文本时(并尝试使视图中的URL可点击),我执行以下操作:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.dataDetectorTypes = UIDataDetectorTypeLink;
...显示类似以下内容:
...看起来好像应该可以工作,但是点击URL时什么都没有发生。我错过了什么吗?
--更新--
尝试根据 Dixit Patel 的答案添加 self.review.editable = NO;
,但没有解决问题:
self.review.text = content;
// My understanding is that this makes URLs clickable...
self.review.editable = NO;
self.review.dataDetectorTypes = UIDataDetectorTypeLink;