IFTweetLabel RegexKitLite открыть UIWebView - PullRequest
0 голосов
/ 08 июля 2011

Я использую IFTweetLabel, и он точно указывает, что он распознает ссылки, но я ужасно долго открываю веб-просмотр с помощью кнопки, которую создает IFTweetLabel.Я запускаю NSLog и ясно вижу, что он понимает каждую ссылку, когда нажимается кнопка, но по какой-то причине он не открывает URL.

Ниже приведен код, который я использую для отображения представления и загрузкистрока в веб-представлении .... которая все работает, кроме загрузки веб-просмотра.

Любые предложения будут очень благодарны!спасибо!

- (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);
}

Ответы [ 2 ]

1 голос
/ 14 февраля 2012

Вот мой код, который должен хорошо работать, но также должен быть очищен:

    - (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 голос
/ 20 августа 2011

Строка, по которой щелкнул пользователь, передается в этот метод и может быть найдена с помощью [объекта уведомления]. То, что вы делаете в своем коде - это передача всего текста внутри вашего твита для веб-просмотра. Поскольку это не URL, ваше приложение будет зависать. Используйте это вместо: [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[notification object]]]];

Вы также можете сначала NSLog [объект уведомления], чтобы убедиться, что это URL.

...