42

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;
Madbreaks
  • 18,119
  • 7
  • 53
  • 69

3 Answers3

62

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

enter image description here

IgniteCoders
  • 4,126
  • 3
  • 40
  • 58
33

Try to use this Hope this help to you

Links are not clickable by default in a UITextView. But luckily they can be enabled with a few simple lines of code:

self.review.editable = NO;//required
self.review.selectable = YES;//required
self.review.dataDetectorTypes = UIDataDetectorTypeLink;

Unfortunately you cannot have an editable UITextView with clickable links. If you set editable to YES, then all links will be treated as regular text.

EDIT

Have u check properly it may be UITextview disable in your .xib file.

Albert Renshaw
  • 16,406
  • 17
  • 99
  • 182
Dixit Patel
  • 6,179
  • 1
  • 31
  • 42
  • Thanks. Added `self.review.editable = NO;` (already had the other part), but still not working. Tried both adding those lines of code before and after setting the view `text`. – Madbreaks Jan 17 '13 at 20:12
  • 2
    @Madbreaks have u check properly it may be UITextview disable in your .xib file. – Dixit Patel Jan 17 '13 at 20:18
  • The issue was that `User Interaction Enabled` wasn't checked at the bottom of the *View* section of IB's *Attributes Inspector*. Thanks for putting me on the right track! – Madbreaks Jan 17 '13 at 20:37
  • Note, you must have `textView.selectable = YES;` for this to work! – Albert Renshaw Apr 14 '19 at 03:22
15

The issue was that User Interaction Enabled wasn't checked at the bottom of the View section of IB's Attributes Inspector.

Madbreaks
  • 18,119
  • 7
  • 53
  • 69