我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。
有没有人知道我到底搞砸了什么才让这一切发生的?
当前回答
确保你实现了tableView:didSelectRowAtIndexPath而不是tableView:didDeSelectRowAtIndexPath
这让我在很多场合!!
其他回答
我也遇到过同样的问题。而且很难找到。但在我的代码中 是这样的:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
它必须返回indexPath,否则-tableView:didSelectRowAtIndexPath:没有被调用。
如果您所单击的单元格被突出显示,但函数仍然没有被调用,请再次检查函数的签名。它应该是这样的:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
你必须检查这个 选择必须是单一选择,编辑必须是在编辑过程中没有选择 你也可以改变uttableviewcell属性中的设置 在表格视图单元格中编辑 样式必须是自定义的,标识符必须是Rid section为none
我刚刚有了这个,就像过去发生在我身上的一样,它没有工作,因为我在尝试添加方法时没有注意自动完成,我实际上最终实现了tableView:didDeselectRowAtIndexPath:而不是tableView:didSelectRowAtIndexPath:。
在我的例子中,问题是将方法声明为private。
这并没有起作用:
private func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
这工作:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {