简体   繁体   English

WKWebView scrollview委托

[英]WKWebView scrollview delegate

I have several page views and each one has a webview. 我有几个页面浏览量,每个都有一个webview。 All references are strong. 所有参考文献都很强。 Everything works fine except the usage of the webview scrollview and setting its delegate. 除了使用webview scrollview并设置其委托外,一切正常。 I use it to listen to scroll events. 我用它来听滚动事件。

When setting the delegate of the webview.scrollview and popping the current view this happens: 设置webview.scrollview的委托并弹出当前视图时,会发生这种情况:

    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: 我在XCode的堆栈跟踪中注意到这发生在:

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. 这在使用UIWebView时运行良好,但现在升级到WKWebView会发生这种情况。 Is there a new way to listen to scroll events? 是否有一种新的方式来收听滚动事件?

Implement the deinit method in your view controller and set the scroll views delegate to nil: 在视图控制器中实现deinit方法,并将滚动视图委托设置为nil:

deinit {
    webView.scrollView.delegate = nil
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM