如何取消UISearchbar中的键盘?
我在我的应用程序中使用 UISearchBar
,它既用作编辑字段又用作搜索。因此,当我想消失键盘时,我必须使用 UISearchBar 中的取消按钮,但我无法在屏幕上显示该取消按钮,那么如何在不使用取消按钮的情况下使键盘在不使用时消失。请帮助我,因为我是 iPhone 应用程序开发的新手。
提前致谢!
I'm using UISearchBar
in my application and it serves as both an edit field as well as a search. So when I want to disappear the keyboard I have to use cancel button in UISearchBar but I can't have that cancel button on screen, so how could T make keyboard disappear when not used without using cancel button. Please help me as i'm new to iPhone application development.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用这个:
只需将 UISearchBar 一词替换为您创建的对象的名称即可。
Use this:
Just replace the word UISearchBar with the name of the object you have created.
您是否正在寻找关闭键盘的方法或如何以编程方式实际执行此操作?如果以编程方式,则
[UISearchBar resignFirstResponder]
。如果您正在寻找一种可能的方法让用户实现这一目标,您可以让键盘上的返回按钮在按下时放弃其第一响应者状态,或者将UIGestureRecognizer
附加到您的视图并进行设置这样当用户在键盘外部单击时,该键盘就会消失。Are you looking for ways you can dismiss the keyboard or how to actually do that programmatically? If programmatically, then
[UISearchBar resignFirstResponder]
. If you are looking for a possible way for the user to achieve that you can either make the return button on the keyboard resign its first responder status when pressed, or attach aUIGestureRecognizer
to your view and set it up so that when the user clicks outside the keyboard, this keyboard goes away.您所需要做的就是从 UISearchbar 获取 UITextfield 控件,然后将 UITextfield 的委托设置为将执行
-(void) textFieldShouldReturn:(UITextField *)textField
的任何委托simply all you need to do is to get UITextfield control from the UISearchbar and then set UITextfield's delegate to whatever delegate that will perform
-(void) textFieldShouldReturn:(UITextField *)textField