在文本字段中输入一个字符时返回键盘
我正在开发一个 iPhone 应用程序,只要我在文本字段中只输入一个字符,我就必须返回键盘。如何实现这一目标,请提出一些解决方案。
谢谢。
I am developing an iphone application in which i have to return keyboard as soon as i type only one character in textfield. How to achieve this please suggest some solution.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
步骤 1:创建一个实现 UITextFieldDelegate 协议的类
步骤 2:在您的实现中,重写方法 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
步骤 3:设置实例委托类的代理作为 UITextField 的委托。
Step 1: Create a class implementing the protocol UITextFieldDelegate
Step 2: In your implementation, override the method - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
Step 3: Set an instance of the delegate class as the delegate of the UITextField.
您必须在 的 文本委托方法中编写代码
,然后在
textFieldDidBeginEditing
中检查字符串的长度you have to write your code in text delegate method of
and then check your length of string in
textFieldDidBeginEditing
在文本字段中添加通知创建代码
并实施
add notification in textField creating code
and implement
我想这就是你正在寻找的东西?
或者,如果您希望它在开始编辑时立即退出,您可以将此代码放入 textFieldDidBeginEditing: delegate 方法中
,检查此链接
https://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html
I guess this is want you are looking for?
Or if you want it to resign as soon as it starts to edit you can put this code in textFieldDidBeginEditing: delegate method
check this link
https://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html