UIWebView - 方案未知

发布于 2024-11-09 08:33:22 字数 919 浏览 0 评论 0原文

我需要一些帮助来处理 UIWebView 中的一些 NSData 对象。点击 UIWebView 内的链接会导致 NSLog 条目:

Scheme unkown, doing nothing: <URL>

这就是我所做的:

我启动一个外部 HTTPGetOperation 来获取 URL 请求的响应。我需要这样做是因为要处理下载文件。响应存储到 NSData 对象中。

然后,我在 HTTPGetOperation 完成时调用的方法中加载该数据:

[myWebView loadData:myNSDataObject MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

到目前为止,UIWebView 正确显示了 myNSDataObject 的内容。

但是,当我尝试点击该内容中的链接时,我会收到一个 NSLog 条目“未知方案,不执行任何操作:”以及该链接的 URL。

注意:点击链接后,不会调用 -webView:shouldStartLoadWithRequest:navigationType: 等委托方法。

注意:委托设置为 [self.myWebView setDelegate:self]

哪些方法创建该 NSLog 条目?

为什么点击链接后不调用委托方法?

有谁知道答案吗?

I need some help handling some NSData object within an UIWebView. Tapping a link inside UIWebView cause a NSLog entry:

Scheme unkown, doing nothing: <URL>

That is what I did:

I start an external HTTPGetOperation to get a response of URL-request. I need to do so because of handling to download files. The response is stored to an NSData object.

Then I load that data within a method that is called when HTTPGetOperation is done:

[myWebView loadData:myNSDataObject MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];

So far, UIWebView shows the content of myNSDataObject correctly.

But, when I try to tap a link inside that content I get a NSLog entry "Unknown scheme, doing nothing: " with the URL of the link.

Notice: After tapping a link the delegate methods like -webView:shouldStartLoadWithRequest:navigationType: are not called.

Notice: the delegate is set to [self.myWebView setDelegate:self]

Which methods creates that NSLog entry?

Why are the delegate methods are not called after tapping a link?

Does anyone knows an answer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初心未许 2024-11-16 08:33:23

链接是如何编码的?它们是 http:// 链接还是自定义的?只要链接采用标准格式,shouldStartLoadWithRequest 方法就可以测试 URL 方案以确定应如何处理它。

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, frame.size.width, frame.size.height - 44.0f)];
webView.delegate = self;

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] scheme] isEqualToString:@"mycustomdata"]) {
        // insert your code here to actually load the correct data
        return NO;
    }
}

如果您的代表没有接到电话,那么您还有其他问题。我还建议实现 didFailLoadWithError、webViewDidFinishLoad 和 webViewDidStartLoad。

How are the links coded? Are they http:// links or are they custom? As long as the link is in standard form, the shouldStartLoadWithRequest method can test the URL scheme to determine how it should be handled.

webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, frame.size.width, frame.size.height - 44.0f)];
webView.delegate = self;

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if ([[[request URL] scheme] isEqualToString:@"mycustomdata"]) {
        // insert your code here to actually load the correct data
        return NO;
    }
}

If your delegate isn't getting called, then you have some other issue. I would also recommend implementing didFailLoadWithError, webViewDidFinishLoad, and webViewDidStartLoad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文