theTweet = [[[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)] autorelease];
theTweet.text = [[tweets objectAtIndex:index] objectForKey:@"text"];
theTweet.dataDetectorTypes = UIDataDetectorTypeLink;
[tweetView addSubview:theTweet];[tweets :index objectForKey:@"text"];包含一个带有http://t.co/######的链接,但看起来UITextView没有检测到http://t.co链接。我需要使用UIWebView来代替吗?
发布于 2014-11-22 00:06:42
我注意到的一件事是,为了让UITextViews识别链接,您需要将设置为。示例:
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];发布于 2013-01-18 04:07:16
试着用这个希望这对你有帮助
默认情况下,在UITextView中不能单击链接。但幸运的是,只需几行简单的代码即可启用它们:
theTweet.editable = NO;
theTweet.dataDetectorTypes = UIDataDetectorTypeLink;不幸的是,你不能有一个带有可点击链接的可编辑的UITextView。如果将可编辑设置为YES,则所有链接都将被视为普通文本。
就像这样。
UITextView *theTweet= [[UITextView alloc] initWithFrame:CGRectMake(65, 10, 225, 65)];
theTweet.text = @"http://t.co/######";
theTweet.editable = NO;
theTweet.dataDetectorTypes = UIDataDetectorTypeLink;
[myview addSubview:theTweet];发布于 2011-09-05 07:21:28
您是否设置了:theTweet.dataDetectorTypes = UIDataDetectorTypeLink; ?
现在,您添加了这些内容,我尝试了以下代码:
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];它在我身上运行得很好。
错误一定在其他地方。(您是否也关闭了可编辑功能?)
https://stackoverflow.com/questions/7302707
复制相似问题