I am trying to show an image (logo) while the WKWebView is loading.
So, looking at other posts, I would put an image on the screen in ViewDidLoad() and hide the image in the didFinish method. But, for some reason, the didFinish method is not working. It does not print that it finished (although the webview does show up on the screen). For this, I also already looked at other posts. But, these mainly suggest to set the delegate of the WKWebView (which I did). Here is my code:
import UIKit
import Foundation
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let myURL = URL(string:"https://www.mijnmedicijn.nl/")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
func webView(_ webView: WKWebView,
didFinish navigation: WKNavigation!){
print("Webview did finish load")
}
func webView(_ webView: WKWebView,
didStart navigation: WKNavigation!){
print("Webview did start laoding")
}
}
What am I doing wrong? Why doesn't the didFinish work? How would I make it work and show an image while loading?