单击输入按钮或搜索按钮时隐藏键盘
我已在工具栏按钮内的 UIBarButtonItem
内添加了 UISearchBar
按钮。
在下面的形式中:
// search bar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[searchBar release];
[buttons addObject:searchBarButtonItem];
现在,当我单击 UISearchBar
键盘时出现问题。我想在单击输入或搜索按钮时隐藏键盘。我该怎么做?
I've added the UISearchBar
button inside the UIBarButtonItem
inside the toolbar button.
In the below form:
// search bar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[searchBar release];
[buttons addObject:searchBarButtonItem];
Now the problem in when I click on the UISearchBar
keyboard appears. I'd like to hide the keyboard on clicking in enter or search button. How can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
实现 UISearchBarDelegate 中的方法:
Implement a method from
UISearchBarDelegate
:对于斯威夫特
For Swift
您需要处理
UISearchBarDelegate
协议 方法。在以下方法中,调用UISearchBar的
-resignFirstResponder
方法。上述委托方法的详细信息可以在 苹果官方文档。我经常在搜索结束时辞去这些委托方法中的第一响应者。
You need to process the
UISearchBarDelegate
protocol methods.In the following methods, call
-resignFirstResponder
method of UISearchBar.The detail of above delegate methods can be found in the Apple official document. I often resign first responder inside those delegate methods as the end of searching.
您可以使用 UIEarchBar 的委托方法
并输入(未测试)
希望这可以帮助您...
you can use UISEarchBar's delegate method
and for enter (not tested)
Hope this helps you...
在头文件中,添加或连接到 UISearchBar 出口:应如下所示:
添加以下内容
然后,在实现器中,在
viewDidLoad
函数中:。然后添加以下函数:
同样如上所述,确保在标头中添加/扩展该函数
UISearchBarDelegate
In the header file, add or connect to the UISearchBar outlet: should look something like this:
Then, in the implementor, add the following:
in the
viewDidLoad
function.Then add the following function:
Also as mentioned above ensure that this is added/extended in the header
UISearchBarDelegate
使用
[textField endEditing:YES];
,它应该适合您,或者您可以创建一个按钮对象并执行[self.buttonObj resignFirstResponder]
use
[textField endEditing:YES];
, it should work for you, or you can create an oject of ur button and do[self.buttonObj resignFirstResponder]