简体   繁体   English

设置UIWebView scrollView委托会导致错误

[英]setting up UIWebView scrollView delegate causes an error

So I have the following code: 所以我有以下代码:

 NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    if ([currSysVer compare:@"5.0" options:NSNumericSearch] != NSOrderedAscending) {
        webScrollView = self.webView_.scrollView;
    } else {
        webScrollView = [self.webView_ defaultScrollView];
    }

webScrollView.delegate = self

and when I scroll it gives me: 当我滚动时,它给了我:

-[UIWebView scrollViewDidScroll:]: unrecognized selector sent to instance 0x8e8610

this doesn't make any sense why the UIWebView is calling the scrollViewDidScroll\\ 这对UIWebView为什么要调用scrollViewDidScroll \\没有任何意义

If you look here , UIWebView conforms to UIScrollViewDelegate. 如果您在此处查看 ,则UIWebView符合UIScrollViewDelegate。 In essence it uses the same delegation, as UIWebView is scrollable (you might say it's a subclass of UIScrollView, though it's not explicitly stated in the documentation, likely a UIScrollView is a piece of the WebView). 从本质上讲,它使用相同的委托,因为UIWebView是可滚动的(您可能会说它是UIScrollView的子类,尽管在文档中没有明确说明,可能是UIScrollView是WebView的一部分)。

I have found the solution for all version 我已经找到所有版本的解决方案

UIScrollView* sv = nil;
    for (UIView* v in  _webview.subviews) {
        if([v isKindOfClass:[UIScrollView class]]){
            sv = (UIScrollView*) v;
            sv.scrollEnabled = NO;
            sv.bounces = NO;

    }
}

The UIWebView HAS-A a scrollView of which it is the delegate, meaning the scrollViewDidScroll : method is implemented by the UIWebView , because you are using the reference the UIWebView provides to its scrollView , you are now saying that you will be handling this callbacks including scrollViewDidScroll :, and clearly you are not which is why when the delegate call happens it fails. UIWebView HAS-A是一个scrollView作为委托的scrollViewDidScroll ,这意味着scrollViewDidScroll :方法是由UIWebView实现的,因为您使用的是UIWebView提供给它的scrollView的引用,所以您现在说将要处理此回调,包括scrollViewDidScroll :,显然您不是,这就是为什么在发生委托调用时会失败。

Why are you trying to assign as the delegate of the webview scrollview?, that behavior is already implemented. 为什么要尝试将其指定为webview滚动视图的委托?,该行为已经实现。 I am not sure it will play nice if you try to alter that behavior, but in either case if you want to be the delegate of the scrollView then you have to implement the UIScrollViewDelegate protocol and then implement the required methods. 我不确定如果尝试更改该行为会很好用,但是无论哪种情况,如果您想成为scrollView的委托,那么您都必须实现UIScrollViewDelegate协议,然后实现所需的方法。

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

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