在 UIWebView 中检测点击 link

Detect click on link in UIWebView

我无法检测到 UIWebView 内的 link 上的点击。不确定我做错了什么,但是在我的 UIWebView.

中单击 link 导航时没有任何记录

这是我的WebViewController

import UIKit

@available(iOS 10.0, *)
class WebsiteViewController: UIViewController, UIWebViewDelegate {

@IBOutlet var backButton: UIBarButtonItem!
@IBOutlet var webview: UIWebView!
@IBOutlet var navigationBar: UINavigationBar!

let user = UserDefaults.standard

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {

    if webview.canGoBack {
        webview.goBack()

        return true
    }

    return false
}

override func viewDidLoad() {
    super.viewDidLoad()

    navigationBar.topItem?.title = ""

    let url = URL(string: "http://" + user.string(forKey: "site")!)

    webview.loadRequest(URLRequest(url: url!))

    //webview.allowsBackForwardNavigationGestures = true

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    print("test log a click")
    print(navigationType)
    return true
}

}

我在这里做错了什么?我看不到。

检查 webview.delegate 是否设置为自己。