多是因爲網頁上html不合規範的問題,使得第一種方法加載完網頁會不調用webViewDidFinishLoad,但用第二種會調用webViewDidFinishLoadhtml
第一種:// 不調用webViewDidFinishLoadweb
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://xxx.com"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];chrome
[self.webView loadRequest:req];ui
第二種:// 調用webViewDidFinishLoadhtm
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://xxx.com"] options:0 error:nil];utf-8
[self.webView loadData:data MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://ad.yuanxc.com"]];it
多是網頁不合乎標準io
如下的網頁使用兩種方法都會調用webViewDidFinishLoadcoding
<!DOCTYPE HTML>meta
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxx</title>
</head>
<body>
<div style="position:absolute; width:100%; height:100%; z-index:-1; left:0; top:0;">
<img src="guanggao.png" height="100%" width="100%" style="left:0; top:0;">
</div>
</body>
</html>