Swift闪退Cannot remove an observer

2020-07-09  本文已影响0人  玉思盈蝶

目前我试了是没问题,但是看Bugly后台崩溃率还挺高的,暴力处理下吧。

override func viewDidLoad() {
    super.viewDidLoad()
    setupSubviews()
    if let url = URL(string: self.urlStr) {
        self.webView.load(URLRequest(url: url))
    }
    webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
    isViewDidLoad = true
}
deinit {
    if isViewDidLoad {
        webView.removeObserver(self, forKeyPath:  #keyPath(WKWebView.estimatedProgress))
    }
}

参考链接:

https://blog.csdn.net/chokshen/article/details/86304028

https://www.jianshu.com/p/b4e95da41ce5

PS:你们有遇到这个问题吗?怎么解决的?本来打算用try catch,但是不能catch住,所以。。。。。。知道的求告知呀!

上一篇 下一篇

猜你喜欢

热点阅读