我正在尝试在iOS 8上的UIWebView中加载网页。委托方法 - webViewDidStartLoad
和webViewDidFinishLoad
正在调用,但页面仍为白色。
我想加载的网址是:
http://us.rd.yahoo.com/finance/news/rss/story/
http://finance.yahoo.com/news/apple-test-australian-corporate-bond-035643114.html
- (void)viewDidLoad
{
[super viewDidLoad];
NSURLRequest *newsUrlRequest = [[NSURLRequest alloc] initWithURL:self.newsArticleURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:newsUrlRequest queue:operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ([data length] > 0 && error == nil) {
[self.newsWebView loadRequest:newsUrlRequest];
}
}];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[self.pageLoadingSpinnger startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self.pageLoadingSpinnger stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:@"The page you requested could not be loaded.\nPlease go back and try again." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil];
[errorAlertView show];
}
答案 0 :(得分:0)
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"Failed to load with error :%@",[error debugDescription]);
}
尝试使用此代码识别您的错误,然后就可以轻松解决。
答案 1 :(得分:0)
我试过以下,这对我来说非常适合。
NSString *strURL = @"http://us.rd.yahoo.com/finance/news/rss/story/*http://finance.yahoo.com/news/apple-test-australian-corporate-bond-035643114.html";
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:strURL]];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-type"];
[myWebView loadRequest:request];