I'm having difficulty including and finalizing the display of a UIActivityIndicatorView ("loading animation"). I've already tried using webViewDidStartLoad and webViewDidFinishLoad, respectively to start and end the animation, but I was not successful. The code I'm using is this:
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var visaoWeb: UIWebView!
@IBOutlet weak var carregamento: UIActivityIndicatorView!
let urlString : String = "http://www.google.com.br"
override func viewDidLoad() {
if let url = NSURL(string: self.urlString) {
let requestObj = NSURLRequest(url: url as URL)
self.visaoWeb.loadRequest(requestObj as URLRequest)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
func webViewDidStartLoad(_ webView: UIWebView) {
self.carregamento.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView) {
self.carregamento.stopAnimating()
}
*/
}
Note: I'm using swift 3.0