tags:

views:

57

answers:

4

hi all.. i want to start activityindicator whenever user press any link on a webview please help....

+1  A: 

Take a look at UIWebViewDelegate Protocol.

It will allow your delegate to be notified whenever the webview is starting to load new content, which, presumably, is the case whenever a link has been pressed. The delegate method you want is webViewDidStartLoad: - in its implementation you could then easily set up or start your activity indicator.

Toastor
+1  A: 

Use the method webViewDidStartLoad: in UIWebViewDelegate.

tob
+1  A: 

If you wanna show network activity indicator just put

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

and then

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

when you wanna hide it

while if you needs UIActivityIndicator

you have to define it in your controller then Outlet it in XIB and then

show

[activityIndicator startAnimating];

hide

[activityIndicator stopAnimating];
Achille
+3  A: 

First assign the ViewController which the UIWebView appears in as its delegate: Do this either by control-dragging from the UIWebView to the File's Owner object in InterfaceBuilder or in code:

[myWebView setDelegate:myViewController];

Then in your ViewController.m file you can now use the delegate methods to detect when pages are being loaded. These delegate methods will be triggered every time a link or new page is loaded in the UIWebView.

- (void)webViewDidStartLoad:(UIWebView *)webView {
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
jkilbride
i voted........
Online