我需要一些帮助。 我想在第一视图控制器中的webView完成后在第二视图控制器中预加载我的webView。
我相信我需要使用通知中心post / observe在我的第二个视图控制器中调用我的loadWebView函数,但不知道如何操作。任何建议都表示赞赏。
FirstViewController.swift
import UIKit;
import WebKit;
class FirstViewController: UIViewController, WKNavigationDelegate {
let webView:WKWebView = WKWebView(frame: CGRectMake(0, 0, UIScreen.main.bounds.width, UIScreen.main.bounds.height))
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
print("loaded!")
webView.isHidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.google.com")
webView.navigationDelegate = self
webView.load(URLRequest(url: url!))
webView.isHidden = true
self.view.addSubview(webView)
}
}
SecondViewController.swift
import UIKit
import WebKit
class SecondViewController: UIViewController, WKNavigationDelegate {
let webView:WKWebView = WKWebView(frame: CGRectMake(0, 0, UIScreen.main.bounds.width, UIScreen.main.bounds.height))
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
print("loaded!")
webView.isHidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
}
func loadWebView() {
let url = URL(string: "https://www.amazon.com")
webView.navigationDelegate = self
webView.load(URLRequest(url: url!))
webView.isHidden = true
self.view.addSubview(webView)
}
}
答案 0 :(得分:0)
在第一个VC中:
<div class="slideshow-container">
<ul class="rslides">
<li><img src="img/img1.jpg" alt=""></li>
<li><img src="img/img2.jpg" alt=""></li>
<li><img src="img/img3.jpg" alt=""></li>
</ul>
<script src="js/sshow.js"></script>
</div>
<div id="continut"></div>
<div id="continut2"></div>
<div id="continut3"></div>
<footer id="footer">
<ul>
<li id="nume">x</li>
<li class="copyright">Copyright Ⓒ 2017</li>
</ul>
</footer>
</div>
在第二个VC中:
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!) {
//Post notification
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WebViewFinishedLoading"), object: nil)
}