iOS webViewDidFinishLoading not being called

ios, uiwebview

Solution

Copy/Paste error.

- (void)webViewDidFinishLoading:(UIWebView *)wv

Should be changed to:

- (void)webViewDidFinishLoad:(UIWebView *)wv

Problem

I have a `UIWebView` and want to display an activity indicator while it is loading. And then hide it when the `webViewDidFinishLoading`. The only problem is that I am getting this `NSURLErrorDomain` error -999 thing going on. After searching around I found this fix which works to not display any error message but my `webViewDidFinishLoading` doesn't ever get called to get rid of my activity indicator and other stuff that I have going on. I guess I could just make a call to the `didFinishLoading` method in my webViewDidFailWithError method if it fails with -999 but that seems super hacky and wrong. Any ideas on how to fix this? edit* I have figured out where the webview was being asked to load twice so I was able to get rid of the error -999. However, it seems neither of the delegate methods are being called unless I try to load the webview twice (in which case the `webViewDidFinishLoading` method is only called once). ``` - (void)viewDidLoad { self.webView.delegate = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refresh) name:@"DidBecomeActive" object:nil]; [super viewDidLoad]; } -(void)refresh{ [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://myapp.com/app/"]]]; self.webView.scrollView.bounces = NO; } - (void)webViewDidFinishLoading:(UIWebView *)wv { NSLog(@"finished loading"); [self.activityInd stopAnimating]; [self.view bringSubviewToFront:wv]; } - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error { NSLog(@"Failed: %@", error); if([error code] == NSURLErrorCancelled){ return; } [self.activityInd stopAnimating]; [[[UIAlertView alloc] initWithTitle:@"Can't find server" message:@"Check your internet connection and try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]show]; } ```

Original source

Related problems