zoukankan      html  css  js  c++  java
  • iOS wkwebview懒加载中遇到的问题

    1、懒加载传值问题

    2、kvo监听影响 (报错:An instance 0x7fd9cb793f30 of class WKWebView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7fd9cdca68b0>)

    1、这是我遇到的问题,也许是个例,就算狗血了点吧

    需求: 当前界面(mainVC)响应点击事件,传值给webviewController(webVC)其中包含网址,此时如果在webVC中对wkwebview进行懒加载并挂代理:

    问题:在mainVC中调用webVC传值时,wkwebview的懒加载就开始了,,,此时如果传值中的网址为空值,webVC中的代理立马报错崩溃,没办法服务器就是会给空的,只能取消懒加载

    //懒加载

    -(WKWebView*)wkWebView{
        //self.debugDescription
        WKWebViewConfiguration * Configuration = [[WKWebViewConfiguration alloc]init];
        //允许视频播放
        Configuration.allowsAirPlayForMediaPlayback = YES;
        // 允许在线播放
        Configuration.allowsInlineMediaPlayback = YES;
        // 允许可以与网页交互,选择视图
        Configuration.selectionGranularity = YES;
        // web内容处理池
        Configuration.processPool = [[WKProcessPool alloc] init];
        //自定义配置,一般用于 js调用oc方法(OC拦截URL中的数据做自定义操作)
        WKUserContentController * UserContentController = [[WKUserContentController alloc]init];
        // 添加消息处理,注意:self指代的对象需要遵守WKScriptMessageHandler协议,结束时需要移除
        [UserContentController addScriptMessageHandler:self name:@"yurong"];
        // 是否支持记忆读取
        Configuration.suppressesIncrementalRendering = YES;
        // 允许用户更改网页的设置
        Configuration.userContentController = UserContentController;
        _wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, self.navigationBar.bottom, ScreenWidth, ScreenHeight-self.navigationBar.bottom) configuration:Configuration];
        _wkWebView.backgroundColor = whiteCo;
        // 设置代理
        _wkWebView.navigationDelegate = self;
        _wkWebView.UIDelegate = self;
        
        return _wkWebView;
    }

    2、

    //注意,观察的移除

    -(void)dealloc{

        

        if ([self isViewLoaded]) {

            [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];

        }

        

        // if you have set either WKWebView delegate also set these to nil here

        [self.wkWebView setNavigationDelegate:nil];

        [self.wkWebView setUIDelegate:nil];

    }

  • 相关阅读:
    testNG参数传递方式
    TestNG超详细教程
    testNG中@Factory详解
    【转】HashMap的工作原理
    shell脚本学习笔记
    awk文本处理知识汇总
    sed文本处理知识点整理
    oracle数据库sql的基本使用
    【转】Java中==、equals、hashcode的区别与重写equals以及hashcode方法实例
    HTML5 indexedDB数据库的入门学习(二)
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7232625.html
Copyright © 2011-2022 走看看