在 UIScrollView 内滚动 UITableView

Scrolling a UITableView inside a UIScrollView(在 UIScrollView 内滚动 UITableView)
本文介绍了在 UIScrollView 内滚动 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView,它是 UIView 的子视图,那么 UIViewUIScrollView 的子视图代码>.如何检测应该滚动 UITableView 的触摸?

I have a UITableView which is a subview of a UIView, then that UIView is a subview of a UIScrollView. How do I detect the touches that should scroll the UITableView?

UITableView 可以很好地获取项目选择事件(选择/点击表格中的单元格),除了您必须在单元格触发之前按住它.但我无法让 UITableView 滚动,它始终是对平移手势作出反应的 UIScrollView.

The UITableView can get item selection events (a cell in the table is selected/tapped) just fine, except that you have to hold down on the cell before it fires. But I can't get the UITableView to scroll, its always the UIScrollView that reacts to the pan gesture.

非常感谢任何帮助.提前致谢!

Any help is greatly appreciated. Thanks in advance!

解决了,虽然我问错了问题.正如 Roman K 指出的那样,它默认情况下确实有效.我认为问题与 UITableView 的一部分超出 UIScrollView 的边界有关(UITableView 超出了UIScrollView).将其设置为正确地适合 UIScrollView 修复了它.

Solved, though I asked the wrong question. It does work by default as Roman K pointed out. I think the problem was related to having a part of the UITableView outside the bounds of the UIScrollView (the UITableView went over the bottom bounds of the UIScrollView). Setting it to correctly fit inside the UIScrollView fixed it.

推荐答案

请确保 UIScrollView 的 属性 delaysContentTouchescanCancelContentTouches 已设置适当地.它们控制 UIScrollView 实例如何将触摸信息传递给它的子视图.默认情况下,delaysContentTouches 设置为 YES.另外,请确保,如果您扩展了 UIScrollViewtouchesShouldBegin:withEvent:inContentView: 允许子视图中的触摸.

Please, make sure that UIScrollView's properties delaysContentTouches and canCancelContentTouches are set appropriately. They control how UIScrollView instance passes touch information to its subviews. By default delaysContentTouches is set to YES. Also, make sure that, if you extended UIScrollView, touchesShouldBegin:withEvent:inContentView: allow touches in the subview.

否则,UITableView 滚动应该在您的场景中默认工作.如果您创建一个仅具有所描述的视图层次结构的测试项目,您将看到情况确实如此.所以,比较两者,看看有什么不同会影响滚动.

Otherwise, UITableView scrolling should work by default in your scenario. If you create a test project with just the view hierarchy as described you will see that it is the case. So, compare the two and see what difference affects the scrolling.

这篇关于在 UIScrollView 内滚动 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
How to use NSURLConnection to connect with SSL for an untrusted cert?(如何使用 NSURLConnection 与 SSL 连接以获得不受信任的证书?)