UIScrollView 中的行选择 UITableView 问题 [英] Issue with row selection UITableView inside UIScrollView
问题描述
我有一个具有以下布局的视图控制器:
I have a view controller with following layout:
- 容器视图
UIScrollView
UITableView
作为UIScrollView
的子视图
- Container View
UIScrollView
UITableView
as a sub view of aUIScrollView
我有另一个
UITableViewController
在其中我有几行和当行被选中时的一些方法.现在我想在UIScrollView
中显示这个UITableview
.所以我将UITableView
添加为UIScrollView
的子视图.表格在滚动视图中显示得很好,但是当我在滚动视图中点击以选择表格的行时,行会被突出显示,但在选择行时不会调用该方法..I have another
UITableViewController
in which I have a few rows and some methods when the row gets selected. Now I want to display thisUITableview
inside theUIScrollView
. So I add theUITableView
as a subview ofUIScrollView
. The table is displayed in the scroll view just fine, but when I tap in the scroll view to select the table's row, then row is being highlighted but the method is not getting called when the row is selected..PBDashboardPickupTable *dashtable = [[PBDashboardPickupTable alloc]initWithNibName:@"PBDashboardPickupTable" bundle:nil]; [self.scrollView addSubview:dashtable.tableView];
我还从界面生成器将滚动视图的
delayContentTouches
设置为YES
并将cancelContentTouch
设置为NO
.另外userInteractionEnabled
设置为YES
... 那么为什么当我点击 table view 的行时没有调用该方法?Also I have set scroll view's
delayContentTouches
toYES
andcancelContentTouch
toNO
from Interface Builder. AlsouserInteractionEnabled
is set toYES
... then why is the method not getting called when I tap the table view's row?推荐答案
Apple 在文档中特别警告避免将
UITableView
放在UIScrollView
中:Apple specifically warns in the documentation to avoid putting a
UITableView
inside of aUIScrollView
:重要:您不应在
UIScrollView
对象中嵌入UIWebView
或UITableView
对象.如果这样做,可能会导致意外行为,因为这两个对象的触摸事件可能会混淆并错误处理.Important: You should not embed
UIWebView
orUITableView
objects inUIScrollView
objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.由于
UITableView
继承自UIScrollView
,我建议您添加您需要的任何其他视图作为tableHeaderView
、tableFooterView代码>,或作为表格中的自定义单元格.
Since
UITableView
inherits fromUIScrollView
, I would suggest you add any additional views you need as atableHeaderView
,tableFooterView
, or as custom cells in the table.这篇关于UIScrollView 中的行选择 UITableView 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!