ios - 如何检测 UIWebView 中的点击事件

标签 ios uiwebview uinavigationcontroller uinavigationbar

我有一个 UITableView 将内容加载到 UIWebView 中,如下所示:

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

Detail view controller with UIWebView HTML content

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

enter image description here

最佳答案

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

-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

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

相关文章:

iphone - UIViewController 添加 subview 给我错误 : unrecognized selector

ios - 不使用盲文屏幕输入调用 textField.shouldChangeCharactersIn

ios - 带有 CGAffineTransform 的 View 的 UIDynamicAnimator

javascript - 如何将对象从 Objective C 传递到 javascript

iOS:返回不属于导航 Controller 的入口点 View Controller

ios - Swift:如何关闭从 AppDelegate 启动的 View Controller 和导航 Controller

ios - 来自不同类的特定实例的 Swift 引用变量

javascript - Webkit 列查找可见文本的范围

ios - 带有 uiwebview swift 的 Gif

ios - 将 UITableViewController 推送到导航堆栈失败