<legend id='LJnyS'><style id='LJnyS'><dir id='LJnyS'><q id='LJnyS'></q></dir></style></legend>

<tfoot id='LJnyS'></tfoot>

          <bdo id='LJnyS'></bdo><ul id='LJnyS'></ul>

        <small id='LJnyS'></small><noframes id='LJnyS'>

      1. <i id='LJnyS'><tr id='LJnyS'><dt id='LJnyS'><q id='LJnyS'><span id='LJnyS'><b id='LJnyS'><form id='LJnyS'><ins id='LJnyS'></ins><ul id='LJnyS'></ul><sub id='LJnyS'></sub></form><legend id='LJnyS'></legend><bdo id='LJnyS'><pre id='LJnyS'><center id='LJnyS'></center></pre></bdo></b><th id='LJnyS'></th></span></q></dt></tr></i><div id='LJnyS'><tfoot id='LJnyS'></tfoot><dl id='LJnyS'><fieldset id='LJnyS'></fieldset></dl></div>

      2. UITextField : 限制输入时允许的最大值(数字)

        时间:2023-05-31

              <bdo id='BiNjJ'></bdo><ul id='BiNjJ'></ul>
            • <legend id='BiNjJ'><style id='BiNjJ'><dir id='BiNjJ'><q id='BiNjJ'></q></dir></style></legend>

                <tbody id='BiNjJ'></tbody>

                <tfoot id='BiNjJ'></tfoot>

                <small id='BiNjJ'></small><noframes id='BiNjJ'>

                • <i id='BiNjJ'><tr id='BiNjJ'><dt id='BiNjJ'><q id='BiNjJ'><span id='BiNjJ'><b id='BiNjJ'><form id='BiNjJ'><ins id='BiNjJ'></ins><ul id='BiNjJ'></ul><sub id='BiNjJ'></sub></form><legend id='BiNjJ'></legend><bdo id='BiNjJ'><pre id='BiNjJ'><center id='BiNjJ'></center></pre></bdo></b><th id='BiNjJ'></th></span></q></dt></tr></i><div id='BiNjJ'><tfoot id='BiNjJ'></tfoot><dl id='BiNjJ'><fieldset id='BiNjJ'></fieldset></dl></div>
                • 本文介绍了UITextField : 限制输入时允许的最大值(数字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有一个UITextField,我想限制该字段中允许的最大输入值为1000.那是当用户在里面输入数字时,一旦输入值大于999,除非用户输入小于 1000 的值,否则输入字段中的值将不再更新.

                  I have a UITextField, I'd like to restrict the maximum allowed input value in the field to be 1000. That's when user is inputting number inside, once the input value is larger than 999, the value in input field won't be updated anymore unless user is inputting value less than 1000.

                  我想我应该使用 UITextField 委托来限制输入:

                  I think I should use UITextField delegate to limit the input:

                  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
                  {
                    //How to do
                  }
                  

                  但我不确定如何实现它.有什么建议吗?

                  But I am not sure how to implement it. Any suggestions?

                  ==========更新=============

                  我的输入框不仅允许用户输入整数,还可以输入浮点值,如 999,03

                  my input field not only allow user to input integer, but also float value like 999,03

                  推荐答案

                  你应该在上面的方法中做以下事情:

                  You should do the following inside the above method:

                  NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
                  
                  //first, check if the new string is numeric only. If not, return NO;
                  NSCharacterSet *characterSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789,."] invertedSet];
                  if ([newString rangeOfCharacterFromSet:characterSet].location != NSNotFound)
                  {
                      return NO;
                  }
                  
                  return [newString doubleValue] < 1000;
                  

                  这篇关于UITextField : 限制输入时允许的最大值(数字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:iOS6 中未调用 shouldAutoRotate 方法 下一篇:iOS 5 Segue 在第一次执行后不工作

                  相关文章

                  最新文章

                • <tfoot id='HTuvq'></tfoot>
                    <i id='HTuvq'><tr id='HTuvq'><dt id='HTuvq'><q id='HTuvq'><span id='HTuvq'><b id='HTuvq'><form id='HTuvq'><ins id='HTuvq'></ins><ul id='HTuvq'></ul><sub id='HTuvq'></sub></form><legend id='HTuvq'></legend><bdo id='HTuvq'><pre id='HTuvq'><center id='HTuvq'></center></pre></bdo></b><th id='HTuvq'></th></span></q></dt></tr></i><div id='HTuvq'><tfoot id='HTuvq'></tfoot><dl id='HTuvq'><fieldset id='HTuvq'></fieldset></dl></div>
                    <legend id='HTuvq'><style id='HTuvq'><dir id='HTuvq'><q id='HTuvq'></q></dir></style></legend>

                        <bdo id='HTuvq'></bdo><ul id='HTuvq'></ul>

                      <small id='HTuvq'></small><noframes id='HTuvq'>