Ios UILabel在UITableViewCell块内带有手势识别器,并选择RowatineXpath

Ios UILabel在UITableViewCell块内带有手势识别器,并选择RowatineXpath,ios,uitableview,uilabel,uitapgesturerecognizer,didselectrowatindexpath,Ios,Uitableview,Uilabel,Uitapgesturerecognizer,Didselectrowatindexpath,我在UITableViewCell中使用了一些带有uitappesturerecognizer的uilabel。手势识别器工作良好。但是当我点击标签时,我希望didSelectRowAtIndexPath:也应该执行。甚至只需indexPathForSelectedRow()方法就可以给出所选行 设置cancelsTouchesInView=false无效 这可能吗?现在,indexPathForSelectedRow()方法返回nil。 谢谢为什么要使用UITapGestureRecognit

我在
UITableViewCell
中使用了一些带有
uitappesturerecognizer
的uilabel。手势识别器工作良好。但是当我点击标签时,我希望
didSelectRowAtIndexPath:
也应该执行。甚至只需
indexPathForSelectedRow()
方法就可以给出所选行

设置
cancelsTouchesInView=false
无效

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

为什么要使用
UITapGestureRecognitizer
?如果要使用它,请尝试将label的标记设置为
label.tag=indexpath.row
。因此,您可能会得到您所看到的价值。根据我自己的意见,我会删除
uitappesturerecognizer
,直接使用
didselectrowatindexpath
方法

编辑2:

尝试使用此解决方案。它可能会对您有所帮助

 -(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;
    }

}

为什么要使用
uitappesturerecognizer
?如果要使用它,请尝试将label的标记设置为
label.tag=indexpath.row
。因此,您可能会得到您所看到的价值。根据我自己的意见,我会删除
uitappesturerecognizer
,直接使用
didselectrowatindexpath
方法

编辑2:

尝试使用此解决方案。它可能会对您有所帮助

 -(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;
    }

}

为什么要使用
uitappesturerecognizer
?如果要使用它,请尝试将label的标记设置为
label.tag=indexpath.row
。因此,您可能会得到您所看到的价值。根据我自己的意见,我会删除
uitappesturerecognizer
,直接使用
didselectrowatindexpath
方法

编辑2:

尝试使用此解决方案。它可能会对您有所帮助

 -(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;
    }

}

为什么要使用
uitappesturerecognizer
?如果要使用它,请尝试将label的标记设置为
label.tag=indexpath.row
。因此,您可能会得到您所看到的价值。根据我自己的意见,我会删除
uitappesturerecognizer
,直接使用
didselectrowatindexpath
方法

编辑2:

尝试使用此解决方案。它可能会对您有所帮助

 -(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;
    }

}

我使用多个标签使用UITapGestureRecognitizer您将做什么?我有三个标签,当我点击它们时,它们将不同的值存储到一个数组中,我需要数组的选定行index@MiteshTrivedi感谢您提供此解决方案。我正试图在tableviewCell中实现一个点击手势,我无意中发现了你的帖子。感谢您分享您的见解!我使用多个标签使用UITapGestureRecognitizer您将做什么?我有三个标签,当我点击它们时,它们将不同的值存储到一个数组中,我需要数组的选定行index@MiteshTrivedi感谢您提供此解决方案。我正试图在tableviewCell中实现一个点击手势,我无意中发现了你的帖子。感谢您分享您的见解!我使用多个标签使用UITapGestureRecognitizer您将做什么?我有三个标签,当我点击它们时,它们将不同的值存储到一个数组中,我需要数组的选定行index@MiteshTrivedi感谢您提供此解决方案。我正试图在tableviewCell中实现一个点击手势,我无意中发现了你的帖子。感谢您分享您的见解!我使用多个标签使用UITapGestureRecognitizer您将做什么?我有三个标签,当我点击它们时,它们将不同的值存储到一个数组中,我需要数组的选定行index@MiteshTrivedi感谢您提供此解决方案。我正试图在tableviewCell中实现一个点击手势,我无意中发现了你的帖子。感谢您分享您的见解!