UITextView dataDetectorTypes无法检测到http://t.co/链接?

nin*_*eer 4 iphone xcode objective-c hyperlink

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

[[tweets objectAtIndex:index] objectForKey:@"text"]; 包含与http://t.co/######的链接,但它似乎不是UITextView检测http://t.co链接.我需要使用UIWebView吗?

Bri*_*tta 9

我注意到的一件事是,为了让UITextViews识别链接,你需要将selectable设置为YES.例:

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];
Run Code Online (Sandbox Code Playgroud)