I'm having some issues with UIWebView not calling delegate methods, which is leading to the network activity indicator not stopping like it should.
Here's the basic steps that lead to an issue:
1. Initial webview loads. Activity indicator starts.
2. webview finishes loading the page. Activity indicator stops. (as expected)
3. push a navigation controller onto the stack
4. select a URL and assign a new URL for the webview
5. post notification of change & pop view controller
6. webview receives notification, activity indicator starts
7. webview finishes loading the page, but never calls webViewDidFinishLoad (or FailLoad).
Here's what I'm seeing in the log:
Code:
webViewDidStartLoad:
Webview retain count: 1
webViewDidFinishLoad:
loadURLFromRequest:
webViewDidStartLoad:
Webview retain count: 1
webViewDidFinishLoad should show up at the end but doesn't. So now I've got a loaded webpage, but a spinner that never stops spinning. Any Ideas?
Here's the code:
Code:
**in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadURLFromRequest:) name:@"loadURLNotification" object:nil];
**sent from pushed controller
[[NSNotificationCenter defaultCenter] postNotificationName:@"loadURLNotification" object:nil];
Code:
-(void)showBookmarks:(id)sender {
BookmarksViewController *showBookmarks = [[BookmarksViewController alloc] init];
[[self navigationController] pushViewController:showBookmarks animated:YES];
[showBookmarks release];
}
Code:
-(void)loadURLFromRequest:(id)sender {
LogMethod();
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *initialURL= [defaults objectForKey:kCurrentURLKey];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:initialURL]]];
[self webViewDidStartLoad:webView];
}
Code:
-(void)webViewDidStartLoad:(UIWebView *)webView {
LogMethod();
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
LogMethod();
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *currentURL = self.webView.request.URL.absoluteString;
urlField.text = currentURL;
}