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;

    }

     
  • 相关阅读:
    hibernate的核心配置
    hibernate的映射配置
    数据库的维护
    索引
    数据库规范化设计
    数据控制DCL
    触发器
    SQL存储过程简介
    Transact-SQL简介
    sysdatabaes表与sysobjects表
  • 原文地址:https://www.cnblogs.com/huangh/p/4174330.html
Copyright © 2011-2022 走看看