Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView scrollview delegate

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?

like image 473
mthandr Avatar asked Dec 06 '22 19:12

mthandr


1 Answers

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

deinit {
    webView.scrollView.delegate = nil
}
like image 175
Thomas Oehri Avatar answered Dec 08 '22 07:12

Thomas Oehri