Iphone TTStyledTextLabel问题,URL为';s
我在我的UITableView的CustomCell中添加了一个TTStyledTextLabel,代码是:Iphone TTStyledTextLabel问题,URL为';s,iphone,objective-c,three20,Iphone,Objective C,Three20,我在我的UITableView的CustomCell中添加了一个TTStyledTextLabel,代码是: TTStyledTextLabel * tt_title = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(50, cell.frame.origin.y, 640, 200)] autorelease]; tt_title.text = [TTStyledText textWithURLs:[[self.posts
TTStyledTextLabel * tt_title = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(50, cell.frame.origin.y, 640, 200)] autorelease];
tt_title.text = [TTStyledText textWithURLs:[[self.posts objectAtIndex:indexPath.row] message]];
tt_title.font = [UIFont systemFontOfSize:15];
tt_title.contentInset = UIEdgeInsetsMake(10, 10, 10, 10);
[tt_title sizeToFit];
[cell addSubview:tt_title
])
传入的NSString有一个URL,但是当我单击该URL时,它什么也不做。。甚至没有在safari中打开它。。这是为什么?在没有看到传递给TTStyledText的实际字符串中有什么内容的情况下,无法确切确定,但作为一种替代方法,您可以尝试使用
[TTStyledText textFromXHTML:[[self.posts objectAtIndex:indexPath.row] message] lineBreaks:NO URLs:YES];
然后将
添加到字符串中字符串只是@“这是www.youtube.com上的测试”这在TTTableViewCell中尝试了您的代码并获得了相同的结果,但通过在前面添加“http://”可以将其转换为链接。所以我猜textWithURLs构造函数没有那么聪明。因此,您有几个选项:1)使用textFromXHTML并使用href锚将字符串转换为标记,2)将http://添加到链接的前面,或3)修改TTStyledText源以仅接受“www.”。希望有帮助!