iOS UIScrollView setScrollEnabled 失败

发布于 2025-01-05 17:17:39 字数 392 浏览 6 评论 0原文

在 iOS5 中,这工作正常:

[descriptionWebView.scrollView setScrollEnabled:NO];

但在任何低于 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'

In iOS5 this works fine:

[descriptionWebView.scrollView setScrollEnabled:NO];

But in any iOS under 5 it fails with:

[UIWebView scrollView]: unrecognized selector sent to instance 0x791f9e0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebView scrollView]: unrecognized selector sent to instance 0x791f9e0'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不会写诗 2025-01-12 17:17:39

问题不在于 setScrollEnabled: 调用。实际上,UIWebViewscrollView 直到 iOS 5 才公开(这就是它在其他方面失败的原因)。请参阅 UIWebView 文档以获取更多信息。

在以前版本的 iOS 中,您必须 诉诸子视图的迭代UIWebView 来查找 UIScrollView

The issue isn't the setScrollEnabled: call. It's actually that the scrollView of the UIWebView wasn't exposed until iOS 5 (which is why it fails on anything else). See the UIWebView documentation for further information.

In previous versions of iOS, you had to resort to iterating through the subviews of your UIWebView to find a UIScrollView.

往事随风而去 2025-01-12 17:17:39

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

if([descriptionWebView respondsToSelector:@selector(scrollView)]){
    [descriptionWebView.scrollView setScrollEnabled:NO];
}

You can do this kind of test which doesn't require you to check which iOS version it is.

if([descriptionWebView respondsToSelector:@selector(scrollView)]){
    [descriptionWebView.scrollView setScrollEnabled:NO];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文