关闭iPad键盘

时间:2013-08-22 13:00:50

标签: iphone ios ipad keyboard

我正在为iPhone和iPad创建一个iOS应用程序,我的一些屏幕有UITextFields。我希望当用户点击文本框时关闭键盘。为此,我编写了以下代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     [firstName resignFirstResponder];
     [lastName resignFirstResponder];
     [email resignFirstResponder];
     [password resignFirstResponder];
     [retypePassword resignFirstResponder];
}

这适用于iPhone,但它对iPad上的键盘不起作用。我在网上搜索过,所有的记忆都不起作用。主要建议是:

- (BOOL)disablesAutomaticKeyboardDismissal {
       return NO;
}

但是这仍然不起作用? 任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:-1)

Add this method to .h file, 
-(IBAction)fn_resign:(id)sender;


Inherit your XIB to UIControl and just add following method to the view.

And in file's owner assign this method to view.

in .m:
-(IBAction)fn_resign:(id)sender{
   //Hide you keyboard.
}