Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView dataDetectorTypes can't detect http://t.co/ links?

    theTweet = [[[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)] autorelease];
    theTweet.text = [[tweets objectAtIndex:index] objectForKey:@"text"];
    theTweet.dataDetectorTypes = UIDataDetectorTypeLink;
    [tweetView addSubview:theTweet];

[[tweets objectAtIndex:index] objectForKey:@"text"]; contains a link with http://t.co/###### but it doesn't seem like the UITextView is detecting http://t.co links. Do I need to use a UIWebView instead?

like image 479
ninjaneer Avatar asked Dec 02 '22 01:12

ninjaneer


2 Answers

One thing I've noticed is that in order for UITextViews to recognize links, you need to set selectable to YES. Example:

self.bodyTextView = [[UITextView alloc]initWithFrame:myFrame];
[self.bodyTextView setEditable:NO];
//this is the key
[self.bodyTextView setSelectable:YES];
[self.bodyTextView setDataDetectorTypes:UIDataDetectorTypeLink];
[self.bodyTextView setAttributedText:myAttributedText];
like image 151
Brian Sachetta Avatar answered Dec 17 '22 19:12

Brian Sachetta


did you set: theTweet.dataDetectorTypes = UIDataDetectorTypeLink; ?

Now that you added that, I tried this code:

    UITextView *theTweet;
theTweet = [[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)];
theTweet.text = @"http://t.co/######";
theTweet.editable = NO;
theTweet.dataDetectorTypes = UIDataDetectorTypeLink;
[myview addSubview:theTweet];

and it works fine with me.

The error must be somewhere else. (did you turn off editable too?)

like image 21
user387184 Avatar answered Dec 17 '22 17:12

user387184