UITapGestureRecognizer中断了UITableView didSelectRowAtIndexPath [英] UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath

查看:210
本文介绍了UITapGestureRecognizer中断了UITableView didSelectRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了自己的函数来在键盘出现时向上滚动文本字段。为了通过点击文本字段来关闭键盘,我创建了一个 UITapGestureRecognizer ,它可以在点击时关闭文本字段上的第一个响应者。

I have written my own function to scroll text fields up when the keyboard shows up. In order to dismiss the keyboard by tapping away from the text field, I've created a UITapGestureRecognizer that takes care of resigning first responder on the text field when tapping away.

现在我还为文本字段创建了一个自动完成功能,在文本字段正下方创建了一个 UITableView 并填充它用户输入文本的项目。

Now I've also created an autocomplete for the textfield that creates a UITableView just below the text field and populates it with items as the user enters text.

但是,当选择自动完成表中的一个条目时, didSelectRowAtIndexPath 没有被召唤。相反,看起来轻敲手势识别器正在被调用并且只是辞职第一响应者。

However, when selecting one of the entries in the auto completed table, didSelectRowAtIndexPath does not get called. Instead, it seems that the tap gesture recognizer is getting called and just resigns first responder.

我猜有一些方法可以告诉轻敲手势识别器继续通过点击消息到 UITableView ,但我无法弄清楚它是什么。任何帮助都将非常感激。

I'm guessing there's some way to tell the tap gesture recognizer to keep passing the tap message on down to the UITableView, but I can't figure out what it is. Any help would be very appreciated.

推荐答案

好的,经过一些搜索手势识别器文档后终于找到了它。

Ok, finally found it after some searching through gesture recognizer docs.

解决方案是实现 UIGestureRecognizerDelegate 并添加以下内容:

The solution was to implement UIGestureRecognizerDelegate and add the following:

////////////////////////////////////////////////////////////
// UIGestureRecognizerDelegate methods

#pragma mark UIGestureRecognizerDelegate methods

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isDescendantOfView:autocompleteTableView]) {

        // Don't let selections of auto-complete entries fire the 
        // gesture recognizer
        return NO;
    }

    return YES;
}

照顾它。希望这对其他人也有帮助。

That took care of it. Hopefully this will help others as well.

这篇关于UITapGestureRecognizer中断了UITableView didSelectRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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