UITableViewCell里带有手势识别器的UILabel块didSelectRowAtIndexPath

我在UITableViewCell使用了UITapGestureRecognizer一些UITapGestureRecognizer 。 GestureRecognizer运行良好。 但是当我点击标签时,我希望didSelectRowAtIndexPath:应该执行。 甚至只是indexPathForSelectedRow()方法应该给我选定的行。

设置cancelsTouchesInView = false不起作用!

这可能吗? 现在indexPathForSelectedRow()方法返回nil。 谢谢

你为什么使用UITapGestureRecognizer ? 如果要使用它,请尝试将标签的标签设置为label.tag=indexpath.row 。 所以你可能会得到你正在看的价值。 关于我自己的意见,我会删除uitapgesturerecognizer并直接使用didselectrowatindexpath方法..

编辑2:

尝试使用这个解决scheme..它可能会帮助你..

  -(void)handleTap:(UITapGestureRecognizer *)sender { CGPoint location = [sender locationInView:self.view]; if (CGRectContainsPoint([self.view convertRect:self.yourTableView.frame fromView:self.tableView.superview], location)) { CGPoint locationInTableview = [self.yourTableView convertPoint:location fromView:self.view]; NSIndexPath *indexPath = [self.yourTableView indexPathForRowAtPoint:locationInTableview]; if (indexPath) [self tableView:self.yourTableView didSelectRowAtIndexPath:indexPath]; return; } }