DisclosureIndicator不检测触摸

我使用UITableViewCellAccessoryDisclosureIndicator作为我的UITableViewCell accessoryType 。 根据苹果的文档,数据源的方法

 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 

应该会自动被调用。

如果单元格已启用,并且附件types为UITableViewCellAccessoryDe​​tailDisclosureButton,则附件视图会跟踪触摸,并在轻敲时向数据源对象发送tableView:accessoryButtonTappedForRowWithIndexPath:消息。

这是我的代码:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } [cell.textLabel setText:[datasource objectAtIndex:indexPath.row]]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } 

数据源方法只是一个NSLog但没有打印…

我错过了什么吗? (当然,数据源和代理设置正确)

答案是在你的问题。 你说

我正在使用UITableViewCellAccessoryDisclosureIndicator作为accessoryType …

你引用了苹果文档的一部分

如果单元格被启用,并且附件types是UITableViewCellAccessoryDe​​tailDisclosureButton …

只有当你使用UITableViewCellAccessoryDetailDisclosureButton是调用的委托方法。 当然,不同之处在于这是一个button, UITableViewCellAccesssoryDisclosureIndicator不是。 当你使用后者时,轻敲它就像敲击单元本身。 您可以创build一个自定义单元格并实现hitTest:确定点击是否“接近”披露指标,但似乎更多的工作比必要(除非你真的不想使用详细披露button)。

检查附件指标的名称UITableViewCellAccessoryNone, UITableViewCellAccessoryDisclosureIndicator, UITableViewCellAccessoryDetailDisclosureButton UITableViewCellAccessoryCheckmark, UITableViewCellAccessoryDetailButton

只有详细的button和详细信息泄露button接收轻敲和调用的方法。 你可以使用UIGestureRecognizer和一个自定义的方法。