UIWebView 不加载数据

UIWebView not loading data

我正在尝试在 iOS 8 上的 UIWebView 中加载网页。委托方法 - webViewDidStartLoadwebViewDidFinishLoad 正在被调用,但页面仍然是白色的。

我要加载的 url 是:

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];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"Failed to load with error :%@",[error debugDescription]);
}

尝试使用此代码找出您的错误,然后您就可以轻松解决它。

我试过跟随,这对我来说很完美。

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];