iOS判断UIWebView加载完成的方法

 UIWebview不同于WkWebview没有加载进度属性来判断加载是否完成了

它有个回调方法

 

- (void)webViewDidFinishLoad:(UIWebView *)webView;

这个方法的苹果官方文档关于它的说明也是含糊的

 

- (void)webViewDidFinishLoad:(UIWebView *)webView

Description

Sent after a web view finishes loading a frame.

Parameters

webView

The web view has finished loading.

Availability

iOS (2.0 and later)

Declared In

UIWebView.h

Reference

UIWebViewDelegate Protocol Reference

通过测试,发现finishLoad方法走了,并非加载完了。

 

结合js方法或许是更加完美的,参考这两篇文章

http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechange.asp

http://www.java2s.com/Book/JavaScript/DOM/document_readyState.htm

 

 NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
      BOOL complete = [readyState isEqualToString:@"complete"];
    if (complete) {
        [self completeProgress];
    }

  

 

posted on 2016-04-18 17:41 wxm5558 阅读(...) 评论(...) 编辑 收藏

公告

统计

  • 随笔 - 32
  • 文章 - 3
  • 评论 - 2