根据当前 URL 使用 UIRefreshControl 刷新
Posted
技术标签:
【中文标题】根据当前 URL 使用 UIRefreshControl 刷新【英文标题】:Refresh using UIRefreshControl depending on current URL 【发布时间】:2013-08-28 22:25:19 【问题描述】:我最近放弃了对我的应用程序的 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");
【问题讨论】:
【参考方案1】:我想我明白了。
字面上不得不改顶部:NSString *string = webView.request.URL.absoluteString;
到目前为止一切顺利。如果我有任何其他问题,我会撞到这个帖子。
【讨论】:
以上是关于根据当前 URL 使用 UIRefreshControl 刷新的主要内容,如果未能解决你的问题,请参考以下文章