如何检查WkWebView是否在Objective-C中完成加载? [英] How to check if WkWebView finish loading in Objective-C?

查看:454
本文介绍了如何检查WkWebView是否在Objective-C中完成加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WkWebView加载HTML页面,并且想要在完成加载后显示该页面.只要加载,我想在一个空的View上显示一个活动指示器. 我创建两个视图loadingView和wkWebView.在页面加载过程中,我将VC作为子视图添加到VC中,并且要删除loadingView并添加wkWebView之后作为子视图.这是我的代码:

    [self addSubview:_loadingView];
    _wkWebView = [[WKWebView alloc] initWithFrame:self.frame];
    _wkWebView.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);

    //Send a request to wkUrlconnection
    NSURL *wkUrl = [NSURL URLWithString:self.wkUrlString];
    NSURLRequest *wkRequest = [NSURLRequest requestWithURL:wkUrl];

    //Here I want to check if it's loaded and then remove loadingView and add wkWebView
    [_wkWebView loadRequest:wkRequest];
    [self.loadingView removeFromSuperview];
    [self addSubview:_wkWebView];

有人可以告诉我如何在加载时进行检查,以及是否完成了刷新VC的工作?谢谢您的回答.

解决方案

我认为WKNavigationDelegate 解决方案

I think the WKNavigationDelegate's webView:didFinishNavigation: delegate callback is what you're looking for.

Configure and present your activity indicator when you start to load and then stop and remove it from view when the callback is called.

这篇关于如何检查WkWebView是否在Objective-C中完成加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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