Answer the question
In order to leave comments, you need to log in
How to reload webview only after page is loaded?
How to reload Webview only after the page is loaded ? That is, I have content in the webview, and when data changes, I need to refresh the webview itself when the data is ready for replacement, that is, do not show a white screen and gradually load the page.
webView = WKWebView(frame: webView.frame)
view.addSubview(webView)
webView.navigationDelegate = self
webView.load(myRequest)
The option to use 2 webviews and change them with each other, well, such a solution.
Answer the question
In order to leave comments, you need to log in
I think this can be done by canceling the load in the delegate method and doing it manually:
func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
URLSession.shared.dataTask(with: navigationAction.request) { [weak webView] (data, _, _) in
decisionHandler(.cancel)
guard let html = data.flatMap({ String(data: $0, encoding: .utf8) }) else {
return
}
webView?.loadHTMLString(html, baseURL: navigationAction.request.url)
}.resume()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question