2013-08-28 42 views
0

我最近放棄了iOS 5對我的應用程序的支持,並使用UIRefreshControl進行了操作。我沒有完全建立和完美工作。我的目標是讓它刷新,如果它在我網站上的當前網址,或者它在另一個網站上,比如youtube,請重新加載並刷新到我的網站。合理?根據當前URL使用UIRefreshControl刷新

到目前爲止,我嘗試過這樣做沒有成功。我去了YouTube,NSLog把它當作我現在的網站。我很困惑,因爲它顯然不是。

任何幫助,將不勝感激。

-(void)handleRefresh:(UIRefreshControl *)refresh { 

    NSString *string = @"MySite.com"; 
    if ([string rangeOfString:@"MySite"].location == NSNotFound) { 

     // Reload my data 
     NSString *fullURL = @"http://www.MySite.com/"; 
     NSURL *url = [NSURL URLWithString:fullURL]; 
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
     [webView loadRequest:requestObj]; 

     [(UIWebView *)[self.view viewWithTag:999] reload]; 
     [overlay postMessage:@"Reloading" duration:1 animated:YES]; 

     //set the title while refreshing 
     refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing the View"]; 
     //set the date and time of refreshing 
     NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init]; 
     [formattedDate setDateFormat:@"MMM d, h:mm a"]; 
     NSString *lastupdated = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]]; 
     refresh.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated]; 
     lastupdated:[UIColor colorWithRed:(87.0/255.0) green:(108.0/255.0) blue:(137.0/255.0) alpha:1.0]; 

     //end the refreshing 
     [refresh endRefreshing]; 
     NSLog(@"String does not contain MySite"); 

    } else { 

     // Reload my data 
     NSString *fullURL = webView.request.URL.absoluteString; 
     NSURL *url = [NSURL URLWithString:fullURL]; 
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
     [webView loadRequest:requestObj]; 

     [(UIWebView *)[self.view viewWithTag:999] reload]; 
     [overlay postMessage:@"Reloading" duration:1 animated:YES]; 

     //set the title while refreshing 
     refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing the View"]; 
     //set the date and time of refreshing 
     NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init]; 
     [formattedDate setDateFormat:@"MMM d, h:mm a"]; 
     NSString *lastupdate = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]]; 
     refresh.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdate]; 
     lastupdate:[UIColor colorWithRed:(87.0/255.0) green:(108.0/255.0) blue:(137.0/255.0) alpha:1.0]; 

     //end the refreshing 
     [refresh endRefreshing]; 
     NSLog(@"String contains MySite"); 
    } 

} 

回答

0

想想我明白了。

字面上必須改變頂端:NSString * string = webView.request.URL.absoluteString;

到目前爲止這麼好。如果我有任何其他問題,它會碰到這個線程。