Say I may have a UIWebView
displays a page which contains a link
. When user clicks the link, is it possible to trigger a event to update native UI
?
For example, when user clicks the link, I want to change the progress value in UIProgressView
. Is there any way to do this? Thank you!
Asked
Active
Viewed 3,557 times
0
-
1What's a `WebUIView` do you mean `UIWebView`? – Popeye Jul 02 '13 at 07:11
-
http://stackoverflow.com/questions/15537320/invoke-method-in-objective-c-code-from-html-code-using-uiwebview/15541607#15541607 look at this question – Vinodh Jul 02 '13 at 09:01
3 Answers
2
Try using this method:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
return TRUE;
}
and you can check the navigationType value:
enum {
UIWebViewNavigationTypeLinkClicked,
UIWebViewNavigationTypeFormSubmitted,
UIWebViewNavigationTypeBackForward,
UIWebViewNavigationTypeReload,
UIWebViewNavigationTypeFormResubmitted,
UIWebViewNavigationTypeOther
};

Benetz
- 447
- 5
- 18
0
You need to implement webView:shouldStartLoadWithRequest:navigationType: protocol method.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// the request variable contains the request the user clicked on.
}

Avi Tsadok
- 1,843
- 13
- 19
0
You can use detecting touch events in the UIWebview by delegate methods below
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"Touches began");
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"Touches moved");
}
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"Touches ended");
}
- (void) touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"Touches cancelled");
}
You have to add the UIWebView covering the main view and add a custom class that extends UIWindow to capture touch events.
You can find a step by step tutorial blog here.

Nazik
- 8,696
- 27
- 77
- 123