代码之家  ›  专栏  ›  技术社区  ›  Daddy

UIKeyboardTypeNumberPad-在iPad上只显示数字?

  •  17
  • Daddy  · 技术社区  · 16 年前

    UIKeyboardTypeNumberPad在iPad上不显示数字键盘。相反,它显示UIKeyboardTypeNumbers和标点符号键盘。

    谢谢你的指导!

    3 回复  |  直到 14 年前
        1
  •  14
  •   Dustin Howett    16 年前

    我相信目前iphoneos3.2在iPad上并不支持这一点

    引用uitraits头文件:

    //
    // UIKeyboardType
    //
    // Requests that a particular keyboard type be displayed when a text widget
    // becomes first responder. 
    // Note: Some keyboard/input methods types may not support every variant. 
    // In such cases, the input method will make a best effort to find a close 
    // match to the requested type (e.g. displaying UIKeyboardTypeNumbersAndPunctuation 
    // type if UIKeyboardTypeNumberPad is not supported).
    //
    
        2
  •  8
  •   Hector    14 年前

    添加 UITextFieldDelegate 在头文件(.h文件)中

    txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
    txtfield_name.delegate=self;
    

    然后添加此方法

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
     NSString *validRegEx =@"^[0-9]*$"; //change this regular expression as your requirement
     NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
     BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
     if (myStringMatchesRegEx)
            return YES;
     else
            return NO;
    }
    
        3
  •  2
  •   acecapades    14 年前

    我知道这个问题已经有很长一段时间没用了,但这可能会对其他人有所帮助。

    你可以尝试实现这个 https://github.com/azu/NumericKeypad