首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IFTweetLabel RegexKitLite打开UIWebView

IFTweetLabel RegexKitLite打开UIWebView
EN

Stack Overflow用户
提问于 2011-07-08 13:01:52
回答 2查看 196关注 0票数 0

我使用的是IFTweetLabel,它能识别链接,但我很难用IFTweetLabel创建的按钮打开一个网页视图。我正在运行NSLog,可以清楚地看到它正在理解每个链接,当按钮被按下时,但由于某种原因,它不会打开网址。

下面是我用来显示视图和在webView....which中加载字符串的代码,除了加载webview之外,所有这些都是有效的。

如有任何建议,我们将不胜感激!谢谢!

代码语言:javascript
复制
- (void)handleTweetNotification:(NSNotification *)notification

{
[UIView beginAnimations:@"animateView" context:nil];
[UIView setAnimationDuration:1.0];

CGRect viewFrame = [MainwebView frame];
viewFrame.origin.x = 220;
MainwebView.frame = viewFrame;        

MainwebView.alpha = 1.0; 
web.alpha = 1.0;

MainwebView.layer.shadowColor = [[UIColor blackColor] CGColor];
MainwebView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
MainwebView.layer.shadowRadius = 8.0f;
MainwebView.layer.shadowOpacity = 1.0f;     



[self.view addSubview:MainwebView];
[UIView commitAnimations];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tweetLabel.text]]]; 

NSLog(@"handleTweetNotification: WTF notification = %@", notification);
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-14 05:24:56

以下是我的代码,它们应该工作得很好,但也应该进行一些清理:

代码语言:javascript
复制
    - (void)handleTweetNotification:(NSNotification *)notification {    

    unichar theChar = [(NSString *)notification.object characterAtIndex:0];
    NSString *theString = (NSString *)notification.object;


    if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"#"]) {
        DLog(@"This is a hashtag");
        theString = [theString stringByReplacingOccurrencesOfString:@"#" withString:@"%23"];
        NSURL *hashtagURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/#!/search?q=%@", theString]];
        WebViewController *theWebVC = [[WebViewController alloc] init];
        theWebVC.request = [NSURLRequest requestWithURL:hashtagURL];
        UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
        [self presentModalViewController:theNavigationVC animated:YES];

    }

    if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"@"]) {
        DLog(@"This is a Mention");
        theString = [theString stringByReplacingOccurrencesOfString:@"@" withString:@""];
        NSURL *mentionURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@", theString]];
        WebViewController *theWebVC = [[WebViewController alloc] init];
        theWebVC.request = [NSURLRequest requestWithURL:mentionURL];
        UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
        [self presentModalViewController:theNavigationVC animated:YES];

    }
    if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"h"]) {
        DLog(@"This is a hyperlink");
        theString = [[theString componentsSeparatedByString: @"\n"] objectAtIndex:0];
        NSURL *hyperlinkURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", theString]];
        WebViewController *theWebVC = [[WebViewController alloc] init];
        theWebVC.request = [NSURLRequest requestWithURL:hyperlinkURL];
        UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
        [self presentModalViewController:theNavigationVC animated:YES];
    }
}
票数 1
EN

Stack Overflow用户

发布于 2011-08-20 16:20:34

用户单击的字符串将传递给此方法,并可通过使用通知对象找到。您在代码中所做的就是将tweetLabel中的所有文本传递给webview。由于这不是一个URL,你的应用程序将崩溃。改用这个:[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[notification object]]]];

您也可以首先对通知对象执行NSLog操作,以确保它是一个URL。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6620151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档