<i id='5u1gY'><tr id='5u1gY'><dt id='5u1gY'><q id='5u1gY'><span id='5u1gY'><b id='5u1gY'><form id='5u1gY'><ins id='5u1gY'></ins><ul id='5u1gY'></ul><sub id='5u1gY'></sub></form><legend id='5u1gY'></legend><bdo id='5u1gY'><pre id='5u1gY'><center id='5u1gY'></center></pre></bdo></b><th id='5u1gY'></th></span></q></dt></tr></i><div id='5u1gY'><tfoot id='5u1gY'></tfoot><dl id='5u1gY'><fieldset id='5u1gY'></fieldset></dl></div>
    <tfoot id='5u1gY'></tfoot>

    <small id='5u1gY'></small><noframes id='5u1gY'>

    <legend id='5u1gY'><style id='5u1gY'><dir id='5u1gY'><q id='5u1gY'></q></dir></style></legend>

    • <bdo id='5u1gY'></bdo><ul id='5u1gY'></ul>

      1. UIWebView didFinishLoading 多次触发

        时间:2023-10-23
        • <legend id='atZQc'><style id='atZQc'><dir id='atZQc'><q id='atZQc'></q></dir></style></legend><tfoot id='atZQc'></tfoot>

            • <i id='atZQc'><tr id='atZQc'><dt id='atZQc'><q id='atZQc'><span id='atZQc'><b id='atZQc'><form id='atZQc'><ins id='atZQc'></ins><ul id='atZQc'></ul><sub id='atZQc'></sub></form><legend id='atZQc'></legend><bdo id='atZQc'><pre id='atZQc'><center id='atZQc'></center></pre></bdo></b><th id='atZQc'></th></span></q></dt></tr></i><div id='atZQc'><tfoot id='atZQc'></tfoot><dl id='atZQc'><fieldset id='atZQc'></fieldset></dl></div>
                <bdo id='atZQc'></bdo><ul id='atZQc'></ul>

                <small id='atZQc'></small><noframes id='atZQc'>

                  <tbody id='atZQc'></tbody>

                1. 本文介绍了UIWebView didFinishLoading 多次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一些代码需要在 UIWebView 完成加载文档后运行.为此,我将 UIWebView 的委托设置为我的控制器,并实现了 webViewDidFinishLoading 方法.

                  I have some code that needs to run after the a UIWebView finishes loading a document. For that I've set the UIWebView's delegate to my controller, and implemented the webViewDidFinishLoading method.

                  这会被多次调用,具体取决于要加载的页面类型.我不确定是不是因为 ajax 请求、图像请求,甚至是 iframe.

                  This gets called multiple times, depending on the type of page to load. I'm not sure if it's because of ajax requests, requests for images, or maybe even iframes.

                  有没有办法告诉主请求已经完成,这意味着 HTML 已完全加载?

                  Is there a way to tell that the main request has finished, meaning the HTML is completely loaded?

                  或者也许延迟我的代码触发,直到所有这些事件都完成触发?

                  Or perhaps delay my code from firing until all of those events are done firing?

                  推荐答案

                  NSLog 跟踪加载开始和结束可能很有启发性(如果你还没有走这么远的话).

                  It could be enlightening (if you haven't gone this far yet) to NSLog a trace of load starts and finishes.

                      - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
                         NSLog(@"Loading: %@", [request URL]);
                         return YES;
                      }
                  
                  
                      - (void)webViewDidFinishLoad:(UIWebView *)webView {
                         NSLog(@"didFinish: %@; stillLoading: %@", [[webView request]URL],
                              (webView.loading?@"YES":@"NO"));
                      }
                  
                  
                      - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
                         NSLog(@"didFail: %@; stillLoading: %@", [[webView request]URL],
                              (webView.loading?@"YES":@"NO"));
                      }
                  

                  我刚刚在我的一个项目中观看了对所有三个的调用,该项目从我的包中加载了一个帮助页面并包含嵌入式资源(外部 css、YUI!、图像).唯一通过的请求是初始页面加载,shouldStartLoadWithRequest 不会为任何依赖项调用.所以很好奇为什么你的 didFinishLoad 被多次调用.

                  I just watched the calls to all three in one of my projects which loads a help page from my bundle and contains embedded resources (external css, YUI!, images). The only request that comes through is the initial page load, shouldStartLoadWithRequest isn't called for any of the dependencies. So it is curious why your didFinishLoad is called multiple times.

                  您所看到的可能是由于重定向,或者如前所述,加载页面中的 ajax 调用.但是您至少应该能够平衡对 shouldStartLoad 和其他两个委托函数中的任何一个的调用,并能够确定加载何时完成.

                  Perhaps what you're seeing is due to redirects, or as mentioned, ajax calls within a loaded page. But you at least should be able balance calls to shouldStartLoad and either of the other two delegate functions and be able to determine when the loading is finished.

                  这篇关于UIWebView didFinishLoading 多次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:处理 UIWebview 内部的触摸 下一篇:UIWebView 是否在请求标头中发送与移动 Safari 相同的用户代理?

                  相关文章

                  <tfoot id='ETyaG'></tfoot>

                    • <bdo id='ETyaG'></bdo><ul id='ETyaG'></ul>

                    <small id='ETyaG'></small><noframes id='ETyaG'>

                    1. <i id='ETyaG'><tr id='ETyaG'><dt id='ETyaG'><q id='ETyaG'><span id='ETyaG'><b id='ETyaG'><form id='ETyaG'><ins id='ETyaG'></ins><ul id='ETyaG'></ul><sub id='ETyaG'></sub></form><legend id='ETyaG'></legend><bdo id='ETyaG'><pre id='ETyaG'><center id='ETyaG'></center></pre></bdo></b><th id='ETyaG'></th></span></q></dt></tr></i><div id='ETyaG'><tfoot id='ETyaG'></tfoot><dl id='ETyaG'><fieldset id='ETyaG'></fieldset></dl></div>

                      <legend id='ETyaG'><style id='ETyaG'><dir id='ETyaG'><q id='ETyaG'></q></dir></style></legend>