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 } }
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.
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.
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.
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.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With