如何在返回按钮点击> iphone上隐藏UIViewController中的键盘 [英] how to hide keyboard in UIViewController on return button click->iphone
问题描述
嗨我发现了一些像这样的问题,但他们谈的是textView,我有ViewController,有scrollView,其中有6个textfield和一个textView,我想要一个功能,让键盘在完成/返回按钮点击时消失。我执行的功能辞职到第一响应者,当我点击scrollView外面时隐藏我的键盘,但这不是我想要的,因为我喜欢让它在点击按钮时消失。
Hi I find some questions like that but they talk about textView, I have ViewController, with scrollView where are 6 textfield and one textView I want a function which makes the keyboard disappear on on done/return button click.I implemented functions resign to first responder, which hide my keyboard when i click outside of scrollView, but that is not exactly i want, because i like to make it disappear on button click too.
任何帮助的谢谢
推荐答案
设置一个符合UITextFieldDelegate协议的类,并使文本字段的委托成为这个班。实现方法:
Set up a class that conforms to the UITextFieldDelegate protocol and make the delegate of your text fields an instance of this class. Implement the method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
如下:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
这篇关于如何在返回按钮点击> iphone上隐藏UIViewController中的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!