UIWebView:加载某些URL时未调用的webViewDidStartLoad / webViewDidFinishLoad委托方法 [英] UIWebView: webViewDidStartLoad/webViewDidFinishLoad delegate methods not called when loading certain URLs

查看:182
本文介绍了UIWebView:加载某些URL时未调用的webViewDidStartLoad / webViewDidFinishLoad委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UIWebView 实现了基本的网络浏览器。我注意到对于某些页面,没有调用 UIWebViewDelegate 方法。

I have basic web browser implemented using a UIWebView. I've noticed that for some pages, none of the UIWebViewDelegate methods are called.

一个示例页面发生这种情况的方法是: http://www.youtube.com/user/google 。以下是重现问题的步骤(确保在控制器的 UIWebViewDelegate 方法中插入 NSLog 调用):

An example page in which this happens is: http://www.youtube.com/user/google. Here are the steps to reproduce the issue (make sure you insert NSLog calls in your controller's UIWebViewDelegate methods):


  1. 将上述youtube网址加载到 UIWebView
    [注意,在这里,页面加载时会调用 UIWebViewDelegate 方法。

  2. 触摸页面上的上传类别

  3. 触摸该类别中的任何视频
    [问题:注意到已加载新页面,但未调用任何UIWebView代理]

  1. Load the above youtube URL into the UIWebView [notice that here, the UIWebViewDelegate methods do get called when the page loads]
  2. Touch the "Uploads" category on the page
  3. Touch any video in that category [issue: notice that a new page is loaded, but none of the UIWebView delegates are called]

我知道这不是 UIWebView 的委托未正确设置的问题,因为委托方法在加载其他链接时调用(例如,如果你尝试点击一条链接将你带到youtube之外,你会注意到调用了委托方法)。

I know that this is not an issue of UIWebView's delegate not being set properly, since the delegate methods do get invoked when loading other links (e.g. if you try clicking on a link that takes you outside of youtube, you'll notice the delegate methods getting called).

My最初的直觉是它可能是因为页面是使用AJAX加载的,这可能不会调用t他委托方法。但是当我检查iPhone的Safari时,它没有出现这个问题,所以它一定是我身边的东西。

My gut feeling initially was that it might be because the page is loaded using AJAX, which may not invoke the delegate method. But then when I checked the iPhone's Safari, it did not exhibit this problem, so it must be something on my side.

我也注意到Three20的 TTWebController 与我有完全相同的问题。

I've also noticed that Three20's TTWebController has the exact same issue as I'm having.

但是这个问题引起的问题是没有委托调用的方法,我无法更新UI以在加载新请求时启用/禁用后退和前进浏览按钮。

But the problem that arises from this issue is that without the delegate methods called, I'm unable to update the UI to enable/disable the back and forward browsing buttons when new requests are loaded.

并了解为什么会发生这种情况或如何我可以解决它在新请求发生时更新UI吗?

And idea why this is happening or how can I work around it to update the UI when a new request is made?

推荐答案

这不是iOS错误 - 页面实际上并没有重新加载。 UIWebView委托是在新页面请求之后触发的,但该页面不会这样做。

This isn't an iOS bug - the page isn't actually reloading. The UIWebView delegates are triggered following new page requests, but that page doesn't do that.

在桌面Safari中发生的事情非常仔细地看 当您按照描述单击该页面上的视频链接时。请务必注意地址栏。地址将会改变,但关键是页面不会重新加载

Look very carefully at what happens in desktop Safari when you click the video link on that page as you describe. Make sure you pay attention to the address bar. The address will change, but critically the page will not reload.

这全部由JavaScript处理,而不是通过重新加载页面。简单地说,页面永远不会重新加载,因此没有理由调用UIWebView代理

This is all handled by JavaScript, not by reloading the page. Simply put, the page never reloads, so there's no reason for the UIWebView delegates to be called.

如果你不相信我,最后证明这个尝试重复您在禁用JavaScript时描述的步骤。您会注意到页面的行为完全不同。

If you don't believe me, to conclusively prove this try repeating the steps you describe with JavaScript disabled. You'll notice the page behaves completely differently.

这篇关于UIWebView:加载某些URL时未调用的webViewDidStartLoad / webViewDidFinishLoad委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆