【问题标题】:UILabel with Gesture Recognizer inside UITableViewCell blocks didSelectRowAtIndexPathUITableViewCell 块中带有手势识别器的 UILabel didSelectRowAtIndexPath
【发布时间】:2014-10-15 21:53:52
【问题描述】:

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

设置cancelsTouchesInView = false 无效!

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

【问题讨论】:

    标签: ios uitableview uilabel uitapgesturerecognizer didselectrowatindexpath


    【解决方案1】:

    您为什么使用UITapGestureRecognizer?如果要使用它,请尝试将标签的标签设置为label.tag=indexpath.row。所以你可能会得到你正在寻找的价值。关于我自己的意见,我会删除 uitapgesturerecognizer 并直接使用 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;
        }
    
    }
    

    【讨论】:

    • 我使用了多个标签
    • 你打算用 UITapGestureRecognizer 做什么??
    • 我有三个标签,当我点击它们时,它们会将不同的值存储到数组中,我需要选择的行作为数组索引
    • @MiteshTrivedi 感谢您提供此解决方案。我试图让一个点击手势在 tableviewCell 中工作,我偶然发现了你的帖子。感谢您分享您的见解!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多