UITextField - 当输入两个数字时,关闭键盘 [英] UITextField - Dismiss keyboard when two digits have been entered

查看:104
本文介绍了UITextField - 当输入两个数字时,关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITextField,它使用数字键盘接受输入。

I have a UITextField, which uses a number pad to take input. How can I dismiss it/run a method call when two digits have been entered into the textField?

推荐答案

-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

   int count = [textField.text length];
    if(count>=2){

    [textField resignFirstResponder];
    }
return YES;
}

这篇关于UITextField - 当输入两个数字时,关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆