我想实现一个功能,一旦我触摸表视图,视图顶部的搜索栏将resignFirstResponder,键盘将从视图中检索。我将以下代码与xib文件中的tableView关联起来,但它似乎不起作用。
- (IBAction)backgroundTap:(id)sender
{
NSLog(@"test : did touch down");
[_searchBar resignFirstResponder];
}我尝试了另一种实现方式,在.m文件中添加以下代码,但仍然不起作用。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"test : did touch down");
UITouch *touch = [touches anyObject];
UIView *view = (UIView *)[touch view];
if (view == self.view) {
[_searchBar resignFirstResponder];
}
}希望有人能帮上忙。
发布于 2013-08-26 12:50:05
就这么做吧..。
[Self.view endEditing:YES];发布于 2013-10-18 23:27:42
试着做你正在做的事情,但是调用resignFirstResponder两次。我发现从iOS 7开始我必须这样做。
https://stackoverflow.com/questions/18431176
复制相似问题