我最近放弃了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");
}
}
答案 0 :(得分:0)
想想我明白了。
字面上必须改变顶部:NSString * string = webView.request.URL.absoluteString;
到目前为止一切顺利。如果我有任何其他问题,那么就会遇到这个问题。