Creare a custom action for an existing button in a webview
I'm displaying an URL on a webview, and on that page there is a button. How can I customi开发者_StackOverflow中文版ze the action that occurs when that button is pressed?
You controller has to respond to <UIWebViewDelegate>
.
Then, override this method:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
NSURL *URL = [request URL];
if ([[URL absoluteString] rangeOfString:@"http://give.it.a.custom.url.to.identify.this.action"].length > 0)
{
// your custom action here
}
return NO;
}
return YES;
}
Don't forget the [youWebView setDelegate:self];
.
精彩评论