zoukankan      html  css  js  c++  java
  • iPad开发中--控制UITextField只允许数字和点的输入

    说明:iPhone开发中如果需要控制UITextField只允许数字和点的话,只需要弹出UIKeyboardTypeDecimalPad样式的键盘即可,但是在iPad中这样不行,需要通过下面方法控制

    #define NUMBERS @"0123456789."

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

    // return NO to not change text

        if (textField.tag == NumberEdit.tag || textField.tag == UnitsPriceEdit.tag) {                NSCharacterSet*cs;

            cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];

            NSString*filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

            BOOL basicTest = [string isEqualToString:filtered];

            if(!basicTest) {

                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"

                                                                message:@"请输入数字或点"

                                                               delegate:nil

                                                      cancelButtonTitle:@"确定"

                                                      otherButtonTitles:nil];

                [alert show];

                return NO;

            }

        }

        return YES;

    }

     
  • 相关阅读:
    spring boot自动配置
    servlet类与Spring Controller类的关系
    Junit中的setup和teardown方法
    dependency的scope
    mapper的namespace
    mybatis缓存
    Ehcache(05)——缓存的查询
    Ehcache(04)——设置缓存的大小
    Ehcache(03)——Ehcache中储存缓存的方式
    Ehcache(02)——ehcache.xml简介
  • 原文地址:https://www.cnblogs.com/huangh/p/4174330.html
Copyright © 2011-2022 走看看