1
I am having difficulty including and finishing the display of a Uiactivityindicatorview ("loading animation"). I have tried using webViewDidStartLoad and webViewDidFinishLoad respectively to start and finish the animation, but I was unsuccessful. 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"
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 am using Swift 3.0
the correct Swift 3 would be
if let url = URL(string: urlString) { visaoWeb.loadRequest(URLRequest(url: url)) }
– Leo Dabus
Thank you @Leodabus, now I feel that the code is slowly evolving. A doubt, it would be appropriate to use self.variavel to refer to variables of the class itself?
– Fábio Jânio