Iphone textfield应删除编辑不';使用UITapGestureRecognitor时不会被调用

Iphone textfield应删除编辑不';使用UITapGestureRecognitor时不会被调用,iphone,ios,objective-c,Iphone,Ios,Objective C,在我的ViewController中,我得到了-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath,但从未调用它。我搜索了为什么这个没有被调用,我发现我使用了这个: UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWit

在我的ViewController中,我得到了
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
,但从未调用它。我搜索了为什么这个没有被调用,我发现我使用了这个:

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

    [self.view addGestureRecognizer:tap];

点击背景时关闭键盘。你知道我该如何解决这个问题吗?不管是在后台点击dismiss键盘还是
didSelectRowAtIndexPath
都能工作吗?

didSelectRowAtIndexPath
永远不会被调用,因为你可能没有实现
UITableViewDelegate

你应该把它和你的控制一起使用,从响应者那里辞职

 [yourTextField resignFirstResponder];

像这样试试它会帮你的

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];
    if(![[touch view] isKindOfClass:[UITextField class]]){

//resign your textfield here
    }

}

如果点击此视图,则执行此操作。您必须重写委托方法
shouldReceiveTouch
,以返回
。如果触摸发生在
tableView

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    // Disallow recognition of tap gestures in the segmented control.
    if ([touch.view isDescendantOfView:self.tblView]) {
        return NO;
    }
    return YES;
}
现在将触发两个委托方法<代码>注意:self.tblView是一个表视图

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
return TRUE;

好吧,看看你是怎么做的。。。。然后,如果可行,请仔细阅读文档以获得详细的解释,这样您就可以清楚地理解。

我确实实现了这一点。当我删除该部分时,导致问题的是TapGestureRecognitor。如果你的ViewConcoller中有textField,当你在方法中点击然后从textField中退出resignFirstResponder时,“dismisskeyboard”方法中的我退出FirstResponder这个方法调用了吗?它会被调用,问题是didSelectRowAtIndexPath没有被调用。请移动该点击手势并放置它。请看我编辑的答案“我这样做了,但如果我单击背景,键盘不会关闭每当我设置UITapGestureRecognitor时,都不会调用didSelectRowAtIndexPath。您的实际要求是什么?
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
return TRUE;