如何在iphone中隐藏虚拟键盘的实现方法

iOS 码拜 9年前 (2015-10-18) 1210次浏览
如何在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

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明如何在iphone中隐藏虚拟键盘的实现方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)