tableView由于可以执行didSelectRowAtIndexPath之前的gestureRecognizer而被隐藏 [英] tableView is hiding due to a gestureRecognizer before it can execute didSelectRowAtIndexPath

查看:56
本文介绍了tableView由于可以执行didSelectRowAtIndexPath之前的gestureRecognizer而被隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理tableViewCell的被窃听,但问题是这是一个临时tableView".我已经对其进行了编码,以便在用户编辑UITextField时将其显示,但是随后我设置了一个手势识别器,以在用户单击UITextField之外的某个位置时将表视图设置为隐藏.

I am trying to handle tableViewCell's being tapped, but the problem is that this is a "temporary tableView". I have it coded so that it will appear while the user is editing a UITextField, but then I set up a gesture recognizer to set the tableview to hidden as soon as the user clicks somewhere away from the UITextField.

我的手势识别器设置如下:

I have the gesture recognizer set up as follows:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                               initWithTarget:self
                               action:@selector(dismissKeyboard)];

[tap setCancelsTouchesInView:NO];
[self.view addGestureRecognizer:tap];

但是,在调用 didSelectRowAtIndexPath 之前先调用dismissKeyboard,所以要处理该事件的TableView变为隐藏状态,因此从不调用此函数.

However, dismissKeyboard is called before didSelectRowAtIndexPath is called, and so the TableView that I want to handle the event on becomes hidden and therefore this function is never called.

我的问题是:是否有人有解决此问题的想法,以便 didSelectRowAtIndexPath 将在tableView隐藏之前执行?我有一个主意,想知道tableView是否是水龙头的来源,如果是,那么不要在dismissKeyboard中执行"hide tableView"行.这可能吗?

My question is: Does anybody have ideas of how to get around this, so that didSelectRowAtIndexPath will execute before the tableView hides? I had one idea to somehow see if the tableView is where the tap is coming from, and if so, then don't execute the "hide tableView" line within dismissKeyboard. Is this possible?

对不起,但是我是iOS开发人员的新手,所以谢谢您的任何建议!

Sorry, but I am new to iOS dev, so thank you for any advice!

推荐答案

您应该能够通过以下操作做到这一点:将视图控制器设为轻击手势的委托,并拒绝它在表格视图中的任何接触.这是一个起点:

You should be able to do this by making your view controller the tap gesture's delegate and denying it any touches that are inside the table view. Here is a starting point:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldReceiveTouch:(UITouch *)touch
{
    //Assuming your table view is a direct subview of the gesture recognizer's view
    BOOL isInsideTableView = CGRectContainsPoint(tableView.frame, [touch locationInView:gesture.view])
    if (isInsideTableView)
        return NO;

    return YES;
}

希望这会有所帮助!

这篇关于tableView由于可以执行didSelectRowAtIndexPath之前的gestureRecognizer而被隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆