美文网首页
页面用到WKWebview, 崩溃报错 [ViewControl

页面用到WKWebview, 崩溃报错 [ViewControl

作者: 溪小希 | 来源:发表于2020-06-09 09:35 被阅读0次

问题: [ViewController retain]: message sent to deallocated instance 0x104655e00

解决办法: 当 ViewController 用到了 WKWebView, 

webView 使用 webView.scrollView.addObserver(self, forKeyPath:"contentSize", options: [.old, .new], context:nil) 动态计算高度, 

需要在 dealloc(swift: deinit) 里面移除通知 webView.scrollView.removeObserver(self, forKeyPath:"contentSize", context:nil), 

并且将 scrollView.delegate 设为 nil

deinit {

        webView.navigationDelegate = nil

        webView.scrollView.delegate = nil

        webView.scrollView.removeObserver(self, forKeyPath:"contentSize", context:nil)

    }

相关文章

网友评论

      本文标题:页面用到WKWebview, 崩溃报错 [ViewControl

      本文链接:https://www.haomeiwen.com/subject/aiojtktx.html