Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

ios - Can't make URL clickable in UITextView

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.

My controller:

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

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

In IB I have:

IB Settings

..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:

Simulator Output

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

--UPDATE--

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Check the "Selectable" and "Links" checkboxes in the textview Attributes Inspector:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...