import UIKit
import WebKit
class ViewControllerMaps: UIViewController, WKUIDelegate {
@IBOutlet weak var ActvityView: UIActivityIndicatorView!
@IBOutlet weak var Videoview: WKWebView!{
didSet {
webView.uiDelegate = self
webView.navigationDelegate = self as? WKNavigationDelegate
}
}
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"//twitter.com/")
let myRequest = URLRequest(url: myURL!)
Videoview.load(myRequest) // ERROR OCCURS HERE
}
func webViewDidStartLoad(_ : WKWebView) {
ActvityView.startAnimating()
NSLog("The webview is started loading")
}
func webViewDidStopLoad(_ : WKWebView) {
ActvityView.stopAnimating()
NSLog("The webview is done loading")
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
DispatchQueue.main.async {
self.ActvityView.stopAnimating()
NSLog("The Webview Has finish Navigating")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
如何阻止可选的nil值出现?我已经注释了他在哪里编写了发生错误的脚本,但是我不确定如何确切地解决它。
X-Code的版本为9.4.1
WKWebview的其他信息委托给它链接到的ViewController。
谢谢:)