本文介绍了关闭UITextField上的键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是为iOS设备开发的新手。我在InterfaceBuilder上插入了一个UITextField,我分配了代码:
I'm a newbie developing for iOS devices. I inserted an UITextField on InterfaceBuilder, and I assigned with the code:
@interface ComposeViewController : UIViewController {
id <ComposeViewControllerDelegate> delegate;
IBOutlet UITextField *notificationTitle;
}
当用户按下返回键时,如何关闭键盘?
How I could allow to close the keyboard when the user press the "Return" key?
推荐答案
将UITextField的Delegate设置为ViewController,在File的Owner和UITextField之间添加一个引用插座,然后实现此方法:
Set the Delegate of the UITextField to your ViewController, add a referencing outlet between the File's Owner and the UITextField, then implement this method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == yourTextField) {
[textField resignFirstResponder];
}
return NO;
}
这篇关于关闭UITextField上的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!