OGeek|极客世界-中国程序员成长平台

标题: ios - 如何检测 UIWebView 中的点击事件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:22
标题: ios - 如何检测 UIWebView 中的点击事件

我有一个 UITableView,可以像这样将内容加载到 UIWebView 中:

//MainViewController.m
- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)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 的所有远程内容都来 self 编写的 Web 服务。第一个屏幕截图是从标题为“词汇表”的 ListView 中选择一个单词时显示的内容

Detail view controller with UIWebView HTML content

这一切都很好,直到您点击链接,在这种情况下,点击 UIWebView 内容中的“框架”链接。新内容已加载,但我需要告诉导航栏 UIWebView 已更改,因此我至少可以更改白色标题文本以匹配新内容。我应该实现哪些 UIWebView 方法以及它们应该去哪里?

enter image description here



Best Answer-推荐答案


将您的 View Controller 设置为 UIWebView 的委托(delegate),然后实现

-(BOOL)webViewUIWebView*)webView shouldStartLoadWithRequestNSURLRequest*)request navigationTypeUIWebViewNavigationType)navigationType

关于ios - 如何检测 UIWebView 中的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9196585/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4