我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
我也有同样的问题,
原因是使用UITapGestureRecognizer。我想让键盘在我点击其他地方时消失。我意识到这覆盖了所有的点击动作,这就是为什么,didSelectRowAtIndexPath函数没有被调用。
当我评论与UITapGestureRecognizer相关的行时,它起作用了。此外,你可以检查UITapGestureRecognizer选择器的功能,如果点击的是UITableViewCell或不是。
其他回答
另一个可能的原因是UITableView被嵌入到UIScrollView中。我今天遇到了这个问题,因为我无意中使用了滚动视图而不是普通视图作为控制器的根视图。
我自己也有这个问题。我已经在IB中构建了视图的骨架(只是一个视图和一个TableView),委托没有设置。我把它连接到文件的所有者,它就像一个魅力。::保存::
以防有人和我犯同样愚蠢的错误
检查您所期望的didSelect的方法名是否会以某种方式意外地获得didDeselect。我花了大约两个小时才发现……
我的问题不在上面。太差劲了。但我想我应该把它列在这里,也许它能帮助到别人。
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.
我知道。别笑。但也许这能帮别人省下我浪费的一小时…
我有问题,控制不进入didselect行后应用断点。问题就在眼前。我从视图中删除了tab手势。那么它运行得很好