Gryph
Gryph

Reputation: 3

activity indicator not hiding when webpage has loaded

In xCode I've put in both the activity indicator and UIWebView aspects, however the activity indicator will not hide after the webpage has loaded. Here's the code, any tips for how I can get this to work?

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

Thanks :)

Upvotes: 0

Views: 374

Answers (1)

Sunny
Sunny

Reputation: 831

First of all you should not use UIWebView it is deprecated. Instead of UIWebView use WKWebView

To stop UIActivityIndicator use WKWebView delegate method

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

You need to follow this link : WKWebView

Upvotes: 1

Related Questions