我使用STTweetLabel来显示tweet,这是我的应用程序中的一个表视图。
我拥有的提要包含指向网站的链接,例如“http://www.google.com”
我想做的是,当用户触摸推特中的链接时,它将打开safari,并将其指向任何链接。
现在发生的事情是,当链接显示在表视图中时,链接会自动打开(用户没有单击它)。
这是我到目前为止检测链接的代码:
@property (nonatomic, strong) NSDictionary *attributesLink;
- (NSDictionary *)attributesForHotWord:(STTweetHotWord)hotWord {
switch (hotWord) {
case STTweetHandle:
return _attributesHandle;
break;
case STTweetHashtag:
return _attributesHashtag;
break;
case STTweetLink:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:_attributesLink]];
return _attributesLink;
break;
default:
break;
}
}编辑:
我的ViewController里也有这个
STTweetLabel *tweetLabel = [[STTweetLabel alloc] initWithFrame:CGRectMake(10.0, 10.0, 300.0, 180.0)];
tweetLabel.text.isAccessibilityElement = YES;
[tweetLabel setText:text];
tweetLabel.textAlignment = NSTextAlignmentLeft;
CGSize size = [tweetLabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:tweetLabel.frame.size.width];
CGRect frame = tweetLabel.frame;
frame.size.height = size.height;
tweetLabel.frame = frame;
tweetLabel.textSelectable = YES;
[tweetLabel setDetectionBlock:^(STTweetHotWord hotWord, NSString *string, NSString *protocol, NSRange range) {
NSArray *hotWords = @[@"Handle", @"Hashtag", @"Link"];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"Link"]];
titleLabel.text = [NSString stringWithFormat:@"%@ [%d,%d]: %@%@", hotWords[hotWord], (int)range.location, (int)range.length, string, (protocol != nil) ? [NSString stringWithFormat:@" *%@*", protocol] : @""];
}];
[cell addSubview:dateLabel];
[cell addSubview:tweetLabel];
}发布于 2014-03-04 12:23:36
解决以下问题:
STTweetLabel *tweetLabel = [[STTweetLabel alloc] initWithFrame:CGRectMake(10.0, 10.0, 300.0, 180.0)];
tweetLabel.text.isAccessibilityElement = YES;
[tweetLabel setText:text];
tweetLabel.textAlignment = NSTextAlignmentLeft;
CGSize size = [tweetLabel suggestedFrameSizeToFitEntireStringConstraintedToWidth:tweetLabel.frame.size.width];
CGRect frame = tweetLabel.frame;
frame.size.height = size.height;
tweetLabel.frame = frame;
tweetLabel.textSelectable = YES;
[tweetLabel setDetectionBlock:^(STTweetHotWord hotWord, NSString *string, NSString *protocol, NSRange range) {
NSArray *hotWords = @[@"Handle", @"Hashtag", @"Link"];
switch (hotWord) {
case STTweetLink:
//Open Safari with the link clicked
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
break;
case STTweetHashtag:
//Preform acton when hashtag is clicked
break;
case STTweetHandle:
//Preform action when username is clicked
break;
default:
break;
}
titleLabel.text = [NSString stringWithFormat:@"%@ [%d,%d]: %@%@", hotWords[hotWord], (int)range.location, (int)range.length, string, (protocol != nil) ? [NSString stringWithFormat:@" *%@*", protocol] : @""];
}];
[cell addSubview:dateLabel];
[cell addSubview:tweetLabel];
}https://stackoverflow.com/questions/22170455
复制相似问题