如何检测 UIWebView 中的点击事件 [英] How to detect a click event in a UIWebView
问题描述
我有一个 UITableView,它可以像这样将内容加载到 UIWebView 中:
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];
}
提供给 UIWebView 的所有远程内容都来自我编写的 Web 服务.第一个屏幕截图是从标题为词汇表"的列表视图中选择一个单词时显示的内容
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"
这一切都很好,直到您点击链接,在这种情况下,点击 UIWebView 内容中的框架"链接.新内容已加载,但我需要告诉导航栏 UIWebView 已更改,因此我至少可以更改白色标题文本以匹配新内容.我应该实现哪些 UIWebView 方法以及它们应该去哪里?
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?
推荐答案
将你的view controller设置为UIWebView的delegate,然后实现
Set your view controller to be the UIWebView's delegate, then implement
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
这篇关于如何检测 UIWebView 中的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!