0
Hi, I’m trying to show the loading indicator while my page is being read, but it didn’t work. I searched the internet, but it doesn’t have the full code and I’m a beginner on Swift. You can help?
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
@IBOutlet weak var indicador1: UIActivityIndicatorView!
@IBOutlet weak var webview: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
loadadress()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadadress(){
let url: URL = URL(string: "http://www.google.com")!
let urlRequest: URLRequest = URLRequest(url: url)
webview.scrollView.isScrollEnabled = false;
webview.scrollView.bounces = false;
webview.load(urlRequest)
}
func webViewDidStartLoad(_: UIWebView){
indicador1.startAnimating()
}
func webViewdDidFinishLoad(_:UIWebView){
indicador1.stopAnimating()
}
}
How’s the
UIActivityIndicatorView
in the view? It appears but does not animate or it does not appear? Could you also check, please, if during the execution, the methodswebViewDidStartLoad
andwebViewdDidFinishLoad
execute?– Marcos Tanaka
It’s in View above webview, debug doesn’t go through didstart or didfinish, I put a print on these functions and didn’t generate anything in the console. When I activate the indicator manually I see over the webview and is activated.
– Roberto Luiz Teixeira Rocha
Okay, so try to implement the
didFinish
ofWKNavigationDelegate
and call theindicador1.stopAnimating()
in it. There theindicador1.startAnimating()
you can call right after thewebview.load(urlRequest)
in his roleloadadress()
.– Marcos Tanaka