iOS UIScrollView setScrollEnabled失败

Jes*_*sse 2 uiwebview uiscrollview ios

在iOS5中,这很好用:

[descriptionWebView.scrollView setScrollEnabled:NO];
Run Code Online (Sandbox Code Playgroud)

但是在任何低于5的iOS中它都失败了:

[UIWebView scrollView]: unrecognized selector sent to instance 0x791f9e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebView scrollView]: unrecognized selector sent to instance 0x791f9e0'
Run Code Online (Sandbox Code Playgroud)

Rya*_*sal 7

问题不在于setScrollEnabled:电话.它实际上是使scrollViewUIWebView是不暴露到iOS 5的(这就是为什么它没有在任何其他).有关UIWebView详细信息,请参阅文档.

在以前的iOS版本中,您不得不求助于遍历的子视图UIWebView来查找UIScrollView.


Joe*_*ets 6

你可以做这种测试,不需要你检查它是哪个iOS版本.

if([descriptionWebView respondsToSelector:@selector(scrollView)]){
    [descriptionWebView.scrollView setScrollEnabled:NO];
}
Run Code Online (Sandbox Code Playgroud)