iOS WKWebView.scrollView delegate cause BAD_ACCESS

孤街浪徒 提交于 2019-12-24 02:45:18

问题


My viewController has a UIView property which contains a WKWebView. And I set the WKWebView scrollView delegate to my viewController, which is a public function of my UIView subClass and called in my viewController.

The issue is when I call [viewController popViewControllerAnimated], it will crash on [UIScrollView setDelegate:]. I have fixed the issue by add viewController.UIView.WKWebView.scrollView.delegate = nil; in viewController's dealloc.

But why? WKWebView's dealloc is after viewController's dealloc, I suppose viewController is set to nil and dealloc in WKWebView will update its delegate to nil then cause BAD_ACCESS? But why dealloc will inplicit call setDelegate???


回答1:


In similar situation for WKWebView I had similar issue on assigning delegate to self. Implementing deinit resolved for me:

deinit {
    webView.scrollView.delegate = nil
}



回答2:


For ObjC, setting the scrollView delegate to nil in dealloc was still causing a crash. Had to nil the delegate in didMoveToSuperview

- (void)didMoveToSuperview {
    if (self.superview == nil) {
        self.scrollView.delegate = nil;
    }
}

These threads helped me

https://github.com/readium/r2-navigator-swift/pull/4

https://bugs.webkit.org/show_bug.cgi?id=159980



来源:https://stackoverflow.com/questions/38733634/ios-wkwebview-scrollview-delegate-cause-bad-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!