1

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

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

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

- (BOOL)disablesAutomaticKeyboardDismissal {
       return NO;
}

但这仍然不起作用?任何帮助将不胜感激。

4

1 回答 1

-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.
}
于 2013-08-22T13:04:09.013 回答