我正在为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/