我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
注意故事板中的UITableView属性,在我的例子中发生的是,我在故事板中选择了combox为“Selection: Single Selection”,这不允许didSelectRowAtIndexPath方法运行。
其他回答
在我的情况下,我犯了一个小错误,我分配:
tableView.isUserInteractionEnabled = false
它应该是:
tableView.isUserInteractionEnabled = true
对此发表我的意见。
我有一个自定义UITableViewCell,有一个按钮覆盖整个单元格,所以当触摸发生时,按钮被选中,而不是单元格。
要么删除按钮,要么在我的情况下,我将按钮上的User interaction Enable设置为false,这样单元格就被选中了。
我的问题不在上面。太差劲了。但我想我应该把它列在这里,也许它能帮助到别人。
I have a tableViewController that is my "base" controller and then I create subclasses of this controller. I was writing all my code in the tableView:didSelectRowAtIndexPath routine in the "base" class. Completely forgetting that by default this routine had also been created (albeit with no code that did anything) in all of my subclasses as well. So when I ran my app, it ran the subclass version of the code, did nothing, and made me sad. So of course, once I removed the routine from the subclasses, it used mt "base" class routine and I'm in business.
我知道。别笑。但也许这能帮别人省下我浪费的一小时…
如果您的表视图处于编辑模式(例如。[tableView setEditing:YES animated:NO];),你需要设置tableView。allowsSelectionDuringEditing = YES;
在我的例子中,我在加载时动态计算TableView的SuperView的高度。由于一个错误的计算,TableView被定位在SuperView之外。TableView绘制得很好,但是所有的交互都被禁用了(并且didSelectRowAtIndexPath从未被调用)。很难检测到,因为没有视觉上的迹象表明TableView是不可访问的。