我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
另一个疯狂的可能性是:我在iPhone 5S上运行我的应用,我使用了:
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
就像我过去一直做的那样。
然而,我没有仔细查看我的编译器警告…它说我应该把上面这一行改为:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
64位兼容性!摇动的拳头
当心,万一你开始扯你的头发。
其他回答
检查- hightforrowatindexpath是否不返回0。
请检查UITapGestureRecognizer。 在我的例子中,tapgesture被添加到tableview所在的视图中,这消耗了UITableview的用户交互,比如didselect。 禁用视图的tapgesture后,触发了didselect委托。
我看了所有的答案,非常同意。但我的情况完全不同。我为detailViewController创建了新的segue直接链接到StoryBoard中的表单元,这就导致了这个。我必须从我的单元格中移除那个segue并将它链接到UITableViewController本身。现在通过编写下面的代码,它可以工作,
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
// Do any operation
performSegue(withIdentifier: "DetailSegue", sender: self)
}
希望这个解决方案能帮助到那些有困难的人!
我的问题不在上面。太差劲了。但我想我应该把它列在这里,也许它能帮助到别人。
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;