UIWebViewDelegate:在页面内导航期间未调用webViewDidFinishLoad [英] UIWebViewDelegate: webViewDidFinishLoad not called during in-page navigation

查看:98
本文介绍了UIWebViewDelegate:在页面内导航期间未调用webViewDidFinishLoad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,用户可以在其中导航一堆本地存储的 HTML 文件。我有一个 UIWebView ,使用 UIWebViewDelegate 正确配置。通常,当用户关注链接时,会调用 shouldStartLoadWithRequest ,稍后再调用 webViewDidFinishLoad

I have an app where users can navigate a pile of locally stored HTML files. I have a UIWebView, configured up correctly with a UIWebViewDelegate. Usually, when the user follows a link, shouldStartLoadWithRequest is called, followed by webViewDidFinishLoad a bit later.

但是,如果链接指向与当前显示的链接相同的页面上的锚点,则仅调用 shouldStartLoadWithRequest webViewDidFinishLoad 不会触发。

But, if the link is pointing to an anchor on the same page as the one which is currently displayed, only shouldStartLoadWithRequest is called. webViewDidFinishLoad does not fire.

从某种意义上说,我看到这可能是预期的行为,因为在页面内导航不应该要求页面重新加载。但是,在页面导航完成后,我真的需要一个可以挂钩调用堆栈的地方。当任何类型的导航结束时,最佳解决方案会让我知道,无论是从另一个页面,页内和向前/向后操作。

In a sense, I see that this might be expected behaviour, because in-page navigation should not require a page reload. However, I really need a place to hook into the call stack after in-page navigation is complete. The optimal solution would let me know when any sort of navigation has ended, both from another page, in-page and forward/backward actions.

到目前为止,我最好的解决方法是在我的 shouldStartLoadWithRequest 方法结束时调用 performSelector:withObject:afterDelay:,但我不满意这个。

My best hackaround so far has been to call performSelector: withObject: afterDelay: at the end of my shouldStartLoadWithRequest method, but I'm not happy with this.

有谁知道我怎么能正确解决这个问题?任何洞察力都赞赏!

Does anyone know how I can solve this correctly? Any insight appreciated!

推荐答案

您可以尝试使用 NSURLConnectionDataDelegate ,它允许您处理传入的数据。也许您可以通过在html文件中添加一个符号来确定是否手动加载页面。

You can try to use NSURLConnectionDataDelegate, it allows you to handle incoming data. Maybe you can determine if the page is loaded manually by adding a sign to your html files.

NSURLConnectionDataDelegate Reference

编辑: gist.github.com/buranmert/7304047 我写了一篇文章代码和它工作,这可能不是你希望它的工作方式,但也许它有所帮助。每次用户单击带锚点的URL时,它都会创建另一个连接,并且当连接完成加载Web视图时,会加载数据,这标记了Web视图完成加载页面的点。由于您只使用本地html文件,我认为创建连接不会产生问题

gist.github.com/buranmert/7304047 I wrote a piece of code and it worked, that may not be the way you wanted it to work but maybe it helps. Every time user clicks a URL with anchor, it creates another connection and as connection finishes loading web view loads the data, that marks the point where web view finished loading the page. As you use only local html files, I do not think creating connections will create problems

这篇关于UIWebViewDelegate:在页面内导航期间未调用webViewDidFinishLoad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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