我想在用户点击UIWebView
上的任何链接时执行某些操作。我这样做是为了完成这项工作:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"request - %@", request.URL.absoluteString);
[webView.window makeKeyAndVisible];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
if(isFirstTimeLoaded)
{
[self shoToolbar];
[self updateButtons];
}
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
isFirstTimeLoaded = YES;
}
这通常可行。但是,当UIWebView
的第一次加载涉及加载页面时的多次重定向时,它并不存在。我想要的是仅在用户有意点击链接时触发此条件。不在UIWebView
的网址重定向上。
答案 0 :(得分:3)
您必须检查navigationType
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType==UIWebViewNavigationTypeLinkClicked) {
// It was a link
} else {
// It wasn't a link
}
return YES;
}