2

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???

Tepmnthar
  • 548
  • 3
  • 23
  • 1
    Could your provide a bit more info? How you added your `scrollView ` to view? with strong reference or not? – iSashok Aug 03 '16 at 04:57

2 Answers2

3

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

deinit {
    webView.scrollView.delegate = nil
}
MobileGeek
  • 2,462
  • 1
  • 26
  • 46
  • 2
    saved my day :-) It was working on iOS > 9 and was crashing on iOS 9. Turns out, that Apple must have fixed it in iOS 10, so that the delegate is now stored weak, instead of string before :-) – alex da franca Mar 15 '18 at 14:40
1

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

akshay1188
  • 1,647
  • 2
  • 17
  • 35