我正在尝试在WkWebView中显示我之前下载并存储在字符串中的html页面。
这就是我设置WkWebView的方式:
webView = WKWebView(frame: self.blankView.frame)
webView.navigationDelegate = self
webView.loadHTMLString(tipShow.htmlString!, baseURL: nil)
view.addSubview(webView)
我想要显示的html字符串是:
<html> <style type="text/css"> * { -webkit-touch-callout: none; -webkit-user-select: none; /*
Disable selection/copy in UIWebView */
}
</style> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,
initial-scale=1">
<title>TITLE</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script
src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script> </head>
<body>
<div data-role="page" id="page1">
<div align=justify style="margin-left:20px; margin-right:20px">
<font size="4.5" face="HelveticaNeue-Light"><br>
<p>
THIS IS A TEST
</p>
</div> </div>
</body></html>
当WkWebView在我的视图中显示时,它将永远存在。
有人可以解释我为什么以及如何解决这个问题?
答案 0 :(得分:11)
<强> SWIFT 强>
你可能会让它有点过于复杂。这对我有用......
首先,导入WebKit
其次,在你的班级下创建一个@IBOutlet:
@IBOutlet weak var webView: WKWebView!
第三,将以下内容放在viewDidLoad()中:
let htmlString:String! = "\(YourString)"
webView.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().bundleURL)
webView.loadHTMLString(htmlString, baseURL: Bundle.main.bundleURL)
答案 1 :(得分:7)
我遇到了和你一样的问题!关键问题在于项目设置:
检查 Xcode项目&gt;目标&gt;能力&gt; App Sandbox 。
确保您已检查过网络✅收件人&amp; ✅传出连接。
见下面的SreenShot:
答案 2 :(得分:0)
此示例说明了如何将HTML插入WKWebView
WKNavigationDelegate
别忘了从strel('line',len,deg)
扩展一个类
get HTML from UIWebView
get HTML from WKWebView
put HTML into UIWebView