我已经完成了以下代码,但我在使用在运行时显示错误的网址加载webview
时出现问题
线程1:信号SIGABRT
所以请帮助我,我刚刚开始macOS
应用程序开发,
谢谢,
import Cocoa
import WebKit
class ViewController: NSViewController, WebFrameLoadDelegate {
@IBOutlet weak var webView: WebView!
let urlpath = NSURL(string: "http://www.google.com/")!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//let url = "https:www.apple.com"
//self.webView.mainFrame.load(NSURLRequest(URL: NSURL(string: url)! as URL))
webView.policyDelegate = self as! WebPolicyDelegate
webView.mainFrame.load(NSURLRequest(url: self.urlpath as URL ) as URLRequest!)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
答案 0 :(得分:1)
您没有实现WebPolicyDelegate
webView.policyDelegate = self as! WebPolicyDelegate
会失败。
self(ViewController)没有实现WebPolicyDelegate。
你需要这样做:
class ViewController: NSViewController, WebFrameLoadDelegate, WebPolicyDelegate {
并实现委托。
还要确保您的webView
@IBOutlet weak var webView: WebView!)
已连接到Interface Builder中的webView!