activity 网页加载后指示器不隐藏

activity indicator not hiding when webpage has loaded

在 xCode 中,我同时添加了 activity 指示器和 UIWebView 方面,但是 activity 指示器不会在网页加载后隐藏。这是代码,关于如何让它工作的任何提示?

 override func viewDidLoad(){
        super.viewDidLoad()
        Videoview.delegate = self as? UIWebViewDelegate;
        loadAdress()
    }
    func loadAdress()  {
        let requestURL = NSURL(string: "https://twitter.com/")
        let request = NSURLRequest(url: requestURL! as URL)
        Videoview.loadRequest(request as URLRequest)
    }
    func webViewDidStartLoad(_  : UIWebView)  {
        ActvityView.startAnimating()
        NSLog("The webview is started loading")
    }
    func webViewDidStopLoad(_  : UIWebView)  {
        ActvityView.stopAnimating()
        ActvityView.isHidden=true;
        NSLog("The webview is done loading")

    }
    func WebViewActvityStopError(_ : UIWebView, didFailLoadWithError error: Error){
        ActvityView.stopAnimating()
        ActvityView.isHidden=true;
        print("Webview fail with error \(error)");
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

谢谢:)

首先你不应该使用 UIWebView 它已被弃用。而不是 UIWebView 使用 WKWebView

要停止 UIActivityIndicator 使用 WKWebView 委托方法

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
     DispatchQueue.main.async {
       // Hide activity indicator here
     }
}

您需要遵循此 link : WKWebView