【问题标题】:shouldStartLoadWithRequest not working when I click on UIWebView当我单击 UIWebView 时,shouldStartLoadWithRequest 不起作用
【发布时间】:2017-07-31 14:51:58
【问题描述】:

我已经用 HTML 内容实现了UIWebView

UIWebView *webView=[[UIWebView alloc] initWithFrame:subView.frame];
webView.delegate=self;
webView.backgroundColor=[UIColor clearColor];
[webView addSubview:chartWebView];
[webView loadHTMLString:htmlContentString baseURL: [[NSBundle mainBundle] bundleURL]];

当 webview 加载委托方法时,它工作正常,但是当我点击一个链接时,shouldStartLoadWithRequest 方法没有被调用。

我写了如下方法:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{   
  if ([[[request URL] absoluteString] hasPrefix:@"ios:"])
  {
      [self performSelector:@selector(getValuesFromWebToNative)];

      return NO;
  }
  return YES;
}

【问题讨论】:

    标签: ios objective-c uiwebview uiwebviewdelegate


    【解决方案1】:

    webViewchartWebView 设置委托,然后尝试,当链接按下时shouldStartLoadWithRequest 函数将调用

    【讨论】:

      【解决方案2】:

      webView 有一个子视图chartWebView。如果链接在chartWebView 中,则可能不会调用委托方法。我无法从您的代码中获得足够的详细信息。您可以发布更多详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-25
        • 1970-01-01
        • 2012-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-10
        相关资源
        最近更新 更多