我正在为 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;
}
但这还是不行? 任何帮助将不胜感激。
最佳答案
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.
}
关于iphone - 关闭 iPad 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18381231/