我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
您可能犯的另一个错误(就像我犯的那样):如果在单元格中设置segue,则不会调用didSelectRowAtIndexPath。你应该在视图控制器中设置segue。
其他回答
另一个可能的原因是UITableView被嵌入到UIScrollView中。我今天遇到了这个问题,因为我无意中使用了滚动视图而不是普通视图作为控制器的根视图。
以防你和我有同样的问题 显然,如果tableView处于编辑模式,这个方法不会被调用。你必须设置allowsSelectionDuringEditing为true。
通过这个问题:编辑时,' UITableView '不调用didSelectRowAtIndexPath ??
我有个电话要打。userInteractionEnabled隐藏在一些定制表代码中。
大多数虫子都很蠢,不是吗?
这些答案对我都没用。大约一个小时后,我发现了一些非常阴险的事情:
我在另一个表格视图的单元格中有一个表格视图。我决定创建一个包含内部表视图的封闭视图。我将这个视图命名为contentView并在xib中连接它。
UITableViewCell已经有一个contentView并对它做了一些奇怪的事情。当我将属性重命名为mainContentView并将视图重新连接到这个重命名的属性时,问题自行解决了。
我的问题不在上面。太差劲了。但我想我应该把它列在这里,也许它能帮助到别人。
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.
我知道。别笑。但也许这能帮别人省下我浪费的一小时…