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];

    }

  • 相关阅读:
    解决ListView异步加载数据之后不能点击的问题
    android点击实现图片放大缩小 java技术博客
    关于 数据文件自增长 的一点理解
    RAC 实例不能启动 ORA1589 signalled during ALTER DATABASE OPEN
    Linux 超级用户的权利
    RAC 实例 迁移到 单实例 使用导出导入
    Shell 基本语法
    Linux 开机引导与关机过程
    RAC 实例不能启动 ORA1589 signalled during ALTER DATABASE OPEN
    Oracle RAC + Data Guard 环境搭建
  • 原文地址:https://www.cnblogs.com/xujiahui/p/7232625.html
Copyright © 2011-2022 走看看