我想在用户按下webview上的任何链接时启动活动指示器.
首先将UIWebView出现的ViewController指定为其委托:通过从UIWebView控件拖动到InterfaceBuilder中的File的Owner对象或代码中来执行此操作:
[myWebView setDelegate:myViewController];
然后在ViewController.m文件中,您现在可以使用委托方法来检测何时加载页面.每次在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]; }