4
votes

I have several page views and each one has a webview. All references are strong. Everything works fine except the usage of the webview scrollview and setting its delegate. I use it to listen to scroll events.

When setting the delegate of the webview.scrollview and popping the current view this happens:

    objc[37721]: Cannot form weak reference to
instance (0x7fb988fe2800) of class WebViewPageController.
    It is possible that this object was over-released,
or is in the process of deallocation.

I notice in the stack trace in XCode that this happens in:

WKWebView dealloc
WKWebView _updateDelegate
UIScrollView setDelegate

What can I do to fix this? This worked well when using UIWebView but now upgrading to WKWebView this happens. Is there a new way to listen to scroll events?

1

1 Answers

15
votes

Implement the deinit method in your view controller and set the scroll views delegate to nil:

deinit {
    webView.scrollView.delegate = nil
}