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

2020-06-09  本文已影响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)

    }

上一篇 下一篇

猜你喜欢

热点阅读