Я пытаюсь загрузить веб-страницу в 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];
}
Зачем использовать 'NSOperationQueue'? Вы можете непосредственно выполнить '[self.newsWebView loadRequest: newsUrlRequest];' после создания 'NSURLRequest * newsUrlRequest'. – iphonic