How to override UIWebView links request action with your own custom method

How to override UIWebView links request action with your own custom method

Ivan Kalaica

If you have a Web View in your view you can call a custom action when the user taps on a link in that UIWebView instance.

Here’s how…

Set the delegate of that UIWebView class instance on your instance of UIViewController class. Now just copy & paste the following code into your class.  This code implements the UIWebView instance and adds a call to the custom action (method).

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
if (overrideLinksSwitch.on == TRUE) {
[self myMethodAction];
[myWebView stopLoading];
return YES;
}
else {
<>return YES;
}
}
return YES;
}

You can download an example app here.

http://surgeworksmobile.com/iphone/how-to-override-uiwebview-links-request-action-with-your-own-custom-method

Posted by 오늘마감
How to override UIWebView links request action with your own custom method

How to override UIWebView links request action with your own custom method

If you have a Web View in your view you can call a custom action when the user taps on a link in that UIWebView instance.

Here’s how…

Set the delegate of that UIWebView class instance on your instance of UIViewController class. Now just copy & paste the following code into your class.  This code implements the UIWebView instance and adds a call to the custom action (method).

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
if (overrideLinksSwitch.on == TRUE) {
[self myMethodAction];
[myWebView stopLoading];
return YES;
}
else {
<>return YES;
}
}
return YES;
}

You can download an example app here.

http://surgeworksmobile.com/iphone/how-to-override-uiwebview-links-request-action-with-your-own-custom-method
Posted by 오늘마감