gpt4 book ai didi

ios - 如何使用 UITapGestureRecognizer 调用 didSelectRowAtIndexPath 方法?

转载 作者:可可西里 更新时间:2023-11-01 03:38:18 25 4
gpt4 key购买 nike

我在 Google 和 Stackoverflow 上搜索了几个小时,尝试过但没有成功。

我在它上面有一个 UITableView tblDepartment 和一个 UISearchBar studentSearch

我添加了一个 UITapGestureRecognizer 以在用户点击搜索框外部时从 studentSearch 文本框中关闭键盘:

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
[self.tblDepartment addGestureRecognizer:gestureRecognizer];

- (void)hideKeyboard
{
[studentSearch resignFirstResponder];
}

之后,当我在 tblDepartment 中选择行时,方法 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 不再被调用。我知道 gestureRecognizer 是原因。

那么,我怎样才能隐藏键盘并仍然允许用户选择行呢?

我试过这段代码,但没有成功:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isDescendantOfView:tblDepartment]) {
return NO;
}
return YES;
}

最佳答案

将手势识别器 cancelsTouchesInView 属性设置为 NO,默认情况下为 YES,如果 GR 识别其手势,它会阻止触摸到达底层 View 。

关于ios - 如何使用 UITapGestureRecognizer 调用 didSelectRowAtIndexPath 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11714686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com