2015-08-17 7 views
0

Я пытаюсь загрузить веб-страницу в UIWebView на iOS 8. Делегированные методы - webViewDidStartLoad и вызываются, но страница остается белой.UIWebView не загружает данные

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]; 
} 
+0

Зачем использовать 'NSOperationQueue'? Вы можете непосредственно выполнить '[self.newsWebView loadRequest: newsUrlRequest];' после создания 'NSURLRequest * newsUrlRequest'. – iphonic

ответ

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

попробовать этот код idenitify свою ошибку, то вы можете решить легко.

Смежные вопросы