我正在尝试禁用wkWebView中的链接加载,所以我正在使用decisionPolicyForNavigationAction,但我的应用程序给了我这个错误:
终止应用程序由于未捕获的异常"NSInternalInconsistencyException"的原因:"完成处理程序传递给 - [视图控制器webView的:decidePolicyForNavigationAction:decisionHandler:]不叫"
这是给我这个错误的简化代码:
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView
required init?(coder aDecoder: NSCoder) {
let config = WKWebViewConfiguration()
self.webView = WKWebView(frame: CGRectZero, configuration: config)
super.init(coder: aDecoder)
self.webView.navigationDelegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.insertSubview(webView, atIndex: 1)
webView.translatesAutoresizingMaskIntoConstraints = false
let height = NSLayoutConstraint(item: webView, attribute: .Height, relatedBy: .Equal, toItem: view, attribute: .Height, multiplier: 1, constant: -44)
let …Run Code Online (Sandbox Code Playgroud)