我最近放弃了对我的应用程序的 iOS 5 支持,并开始使用 UIRefreshControl。我的设置和工作并不完美。我从这个线程的目标是让它刷新,如果它是我网站中的当前网址,或者如果它在另一个网站(如 youtube)上,让它重新加载并刷新回我的网站。说得通?
到目前为止,我已经尝试过这样做但没有成功。我去了 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");
}
}