Why does a UIWebView instance not call scrollViewDidScroll?

扶醉桌前 提交于 2019-12-06 19:02:48

问题


iOS documention says, that the UIWebView class conforms to UIScrollViewDelegate. But an UIWebView instance does not call the scrollViewDidScroll method of its controller. The delegate is set just right by

[webView setDelegate:self];

and webViewDidFinishLoad is called successfully. The controller implements both delegates, UIWebViewDelegate and UIScrollViewDelegate, like this:

@interface WebviewController : UIViewController<UIWebViewDelegate, UIScrollViewDelegate>{
    UIWebView *webView;
}

Browsing SO leads to that category solution:

@implementation UIWebView(CustomScroll)
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.delegate scrollViewDidScroll: scrollView];
}
@end

That category approach does basically the same: Calling the delegate's scrollViewDidScroll method. So why does the the first approach not work?


回答1:


My guess is you set up delegate only for UIWebView. Try setting delegate of scrollView.

webView.scrollView.delegate = self

it should be ok.




回答2:


This is not correct. If you will use:

@implementation UIWebView(CustomScroll)
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.delegate scrollViewDidScroll: scrollView];
}
@end

You will lose focus when try to enter data on page on iOS7 and more

You need to implement custom class for UIWevView and overwrite scrollViewDidScroll:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
[super scrollViewDidScroll:scrollView];
[((id<UIScrollViewDelegate>)self.delegate) scrollViewDidScroll:scrollView];}


来源:https://stackoverflow.com/questions/12093826/why-does-a-uiwebview-instance-not-call-scrollviewdidscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!