Lee Armstrong
Lee Armstrong

Reputation: 11452

UIWebView didn't quite finish loading

I have pushed a view onto my nav controller that contains a UIWebView and this will load a URL.

When it starts I kick off the networkActivityIndicatorVisible and when it finishes I hide it.

If a user decides he does not want to finish loading the web page and hits back on the navcontroller the network indicator carries on. How do I get rid of this as there appears to be no delegate method for this and none of the viewdidUnload get triggered....

Upvotes: 0

Views: 1417

Answers (3)

Rotem
Rotem

Reputation: 21

I did a simple solution of reference counting for the loading processes:

-(void)webViewDidStartLoad:(UIWebView *)webView {

    if (_loadRef == 0) {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    }

    _loadRef++;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {

    _loadRef--;

    if (_loadRef == 0) {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    }
}

Upvotes: 2

lostInTransit
lostInTransit

Reputation: 70997

In the viewWillDisappear: method of your UIWebView's ViewController, do this

if([yourWebView isLoading]){
  //hide your network activity indicator
  [yourWebView stopLoading];
}

Hope that helps

Upvotes: 2

Anh
Anh

Reputation: 6533

How about making the activity indicator invisible in previous controller's viewWillAppear:(BOOL)animated?

Upvotes: 0

Related Questions