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

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


当前回答

我刚遇到这个问题,但它并没有马上发生;在选择了几个单元格之后,它们将停止调用didSelectItemAtIndexPath。我意识到问题是集合视图将allowmultipleselection设置为TRUE。因为单元格从未被取消选择,这阻止了未来调用didSelectItemAtIndexPath。

其他回答

添加@interface ExampleViewController () <UITableViewDelegate, UITableViewDataSource> 在故事板中进行委托

添加代码 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSString *cellText = cell.textLabel.text; }

我不能评论,写在这里。 在我的情况下didSelectRow工作,但没有didDeselectRow。 我为tableView设置委托和数据源,这解决了我的情况。

我的问题不在上面。太差劲了。但我想我应该把它列在这里,也许它能帮助到别人。

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.

我知道。别笑。但也许这能帮别人省下我浪费的一小时…

在我的例子中,只有一个细胞有这个问题。单元格以只读模式包含UITextView出口。虽然在点击前是只读的。一敲键盘,键盘就竖起来了。事实证明,它仍然需要禁用交互。

cell.content.scrollEnabled = NO;
cell.content.editable = NO;
cell.content.userInteractionEnabled = NO;
cell.content.delegate = nil;

[cell。content resignFirstResponder];

确保你实现了tableView:didSelectRowAtIndexPath而不是tableView:didDeSelectRowAtIndexPath

这让我在很多场合!!