我正在编写一个带有tab视图中的表视图的iOS应用程序。在我的UITableViewController中,我实现了-tableView:didSelectRowAtIndexPath:,但当我在运行时选择一行时,该方法没有被调用。表格视图正在被填充,所以我知道控制器中的其他tableView方法正在被调用。

有没有人知道我到底搞砸了什么才让这一切发生的?


当前回答

如果你看了这个,那么问题还是没有解决。

我有自定义单元格,其中复选框“用户交互启用”是禁用的。所以,我只要打开它。祝你好运。

其他回答

即使另一个答案已经被接受,我将为观察这个问题的人补充一个可能的问题和解决方案:

If you have automatic reference counting (ARC) turned on, you may find that even after assigning your controller as a delegate of the view, the view's messages to the controller are not being received because ARC is deleting the controller. Apparently the UITableView's delegate pointer does not count as a reference for the ARC, so if that is the only reference to it, the controller will be dealloc'd. You can verify whether or not this is happening by implementing the dealloc method on the controller and setting a breakpoint or NSLog call there.

解决方案是在其他地方使用强引用跟踪控制器,直到确定不再需要它为止。

听起来好像这个类不是表格视图的UITableViewDelegate,尽管UITableViewController应该自动设置。

你是否有机会将委托重置为其他类?

在我的情况下,问题是我有一个UITableViewCell子类,我实现了这两个方法: touchesBegan:withEvent: & touchesEnded:withEvent处理一个花哨的触摸动画。 但是我忘记添加[super touchesBegan: touchwithevent:event];方法ad [super touchesEnded: touchwithevent:event];也通知父单元的触摸。

所以将代码更改为以下解决了我的问题:

-(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
    [super touchesBegan:touches withEvent:event];
    //blah blah blah
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesEnded:touches withEvent:event];
    //rest of the code
}

你必须检查这个 选择必须是单一选择,编辑必须是在编辑过程中没有选择 你也可以改变uttableviewcell属性中的设置 在表格视图单元格中编辑 样式必须是自定义的,标识符必须是Rid section为none

对此发表我的意见。

我有一个自定义UITableViewCell,有一个按钮覆盖整个单元格,所以当触摸发生时,按钮被选中,而不是单元格。

要么删除按钮,要么在我的情况下,我将按钮上的User interaction Enable设置为false,这样单元格就被选中了。