使用swift在WKWebView上显示活动指示器 [英] Displaying activity indicator on WKWebView using swift

查看:162
本文介绍了使用swift在WKWebView上显示活动指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理以下代码并尝试在页面加载时在视图中显示活动指示器。

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

我试图实现 WKNavigationDelegate 方法,但我失败了,因为没有显示。

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

有关如何解决此问题的任何建议吗?

Any suggestions on how to fix this?

我没有设置SupportWebView视图委托在任何地方,但我不知道如何在swift中进行..

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
    }
}


推荐答案

如评论所述,您忘记设置 webView 委托:

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
}

这篇关于使用swift在WKWebView上显示活动指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆