views:

29

answers:

1

I have a UIWebController embedded in a UIViewController.
I write the HTML code for the UIViewcontroller so I have complete control over the HTML page.

When the user clicks a button in the HTML page - can the containing UIViewController be notified about it?

Can the UIWebView send/raise an event to the UIViewControler?

A: 

You need to implement the webView:shouldStartLoadRequest:navigationType: delegate method for your web view (Apple Docs).

Here's a quick example:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *url = [request URL];
    if ([[url scheme] isEqualToString:@"someLinkURL"]) {

        // Display alert
        UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"I'm a message!" delegate:self cancelButtonTitle:@"Okay!" otherButtonTitles:nil];
        [myAlert show];
        [myAlert release];
        return NO;
    }
    return YES;
}

Your VC must be the webViewDelegate for this method to work.

If you want to handle all clicks manually (i.e. don't go to other pages in the web view) return NO on that final line.

MishieMoo