网页加载后活动指示器未隐藏

时间:2018-08-30 11:06:19

标签: ios iphone xcode uiwebview uiactivityindicatorview

在xCode中,我同时输入了活动指示器和UIWebView方面,但是在加载网页后,活动指示器将不会隐藏。这是代码,有关如何使它起作用的任何提示?

 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()
    }
}

谢谢:)

1 个答案:

答案 0 :(得分:1)

首先,您不应该使用UIWebView。代替UIWebView使用WKWebView

要停止UIActivityIndicator,请使用WKWebView委托方法

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

您需要点击以下链接:WKWebView