iphone中暗藏虚拟键盘的实现

iphone中隐藏虚拟键盘的实现
原问题来自于CSDN问答频道,更多解决方案见http://ask.csdn.net/questions/43

原问题:
如何在iphone中隐藏键盘?
有两个uiTextFields ,但是按了返回键之后键盘不能隐藏。
不知道该怎么办

在你的View或ViewController开始时要设置UITextFieldDelegate 协议:

@interface YourViewController : UIViewController <UITextFieldDelegate>

然后在.m文件中添加UITextFieldDelegate Protocol方法:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{   [textField resignFirstResponder];   return YES;}

最后,初始化.m文件中的textfield后,
yourTextField=[[UITextField alloc] initWithFrame:yourFrame];

下一行非常重要
yourTextField.delegate = self; //viewcontroller或者view关联到textField