views:

501

answers:

3

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....

A: 

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

QAD
Thanks, I was being a muppet then and missed off the :(BOOL)animated and I take it that is required....
Lee Armstrong
+2  A: 

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

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

Hope that helps

lostInTransit
As below, I was being a muppet then and missed off the :(BOOL)animated and I take it that is required....I have added both bits of code.
Lee Armstrong
+1  A: 

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];
    }
}
Rotem