Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying activity indicator on WKWebView using swift

Tags:

I am working on the following code and trying to show an activity indicator in the view whilst the page is loading..

I tried to implement the WKNavigationDelegate methods but I am failing as nothing shows.

Any suggestions on how to fix this?

I am not setting the SupportWebView view delegate anywhere but I wouldn't know how to do it in swift..

import UIKit import WebKit  class SupportWebView: UIViewController, WKNavigationDelegate {     @IBOutlet var containerView : UIView? = nil      var webView: WKWebView?      override func loadView() {         super.loadView()         self.webView = WKWebView()         self.view = self.webView     }      override func viewDidLoad() {         super.viewDidLoad()          var dataManager = DataManager.sharedDataManager()         var url = dataManager.myValidURL         var req = NSURLRequest(URL:url!)         self.webView!.loadRequest(req)     }      override func didReceiveMemoryWarning() {         super.didReceiveMemoryWarning()         // Dispose of any resources that can be recreated.     }      func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {         UIApplication.sharedApplication().networkActivityIndicatorVisible = true     }       func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {         UIApplication.sharedApplication().networkActivityIndicatorVisible = false     } } 
like image 552
mm24 Avatar asked Mar 31 '15 15:03

mm24


People also ask

How do I display activity indicator in Swift?

Select the Assistant Editor and make sure the ViewController. swift is visible. Ctrl and drag from the Start Button to the ViewController class and create the following Action. Ctrl and drag from the Stop Button to the ViewController class and create the following Action.

Is WKWebView the same as Safari?

WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.

What is WKWebView in Swift?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

How do I migrate from UIWebView to WKWebView?

Step-1: Firstly, create a new project with a Single View App. Step-2: Then, open “Main. storyboard” and on your ViewController's view drag “Webkit View”. Select a WKWebView and place it on your view of a view controller.


1 Answers

As commented, you forgot to set the webView delegate:

override func loadView() {     super.loadView()     self.webView = WKWebView()     self.webView.navigationDelegate = self     self.view = self.webView } 
like image 135
Diogo T Avatar answered Sep 27 '22 20:09

Diogo T