How to detect a click event in a UIWebView
11,375
Set your view controller to be the UIWebView's delegate, then implement
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
Comments
-
Slinky almost 2 years
I have a UITableView that loads content into a UIWebView like this:
//MainViewController.m - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { CGRect bounds = [ [ UIScreen mainScreen ] applicationFrame ]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:bounds]; UIWebView *htmlView = [ [ UIWebView alloc ] initWithFrame:[scrollView bounds]]; htmlView.frame = CGRectMake(10,10,280,360); NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [htmlView loadRequest:requestObj]; scrollView.contentSize = [htmlView bounds].size; [scrollView addSubview:htmlView]; [detailsViewController.view addSubview:htmlView]; [htmlView release]; htmlView = nil; [scrollView release]; scrollView = nil; [[self navigationController] pushViewController:detailsViewController animated:YES]; [detailsViewController release]; }
All of the remote content that gets fed to the UIWebView comes from a web service that I wrote. The first screenshot is what is presented when a word is selected from the list view titled "Glossary"
This all is great until you follow a link, in this case clicking on the "frame" link in the UIWebView content. The new content gets loaded but I need to tell the nav bar that the UIWebView has changed so I can at least change the white title text to match the new content. What UIWebView methods should I implement and where should they go?