2010-04-08 9 views
17

UIKeyboardTypeNumberPad no muestra un teclado numérico en el iPad. En cambio, muestra el teclado UIKeyboardTypeNumbersAndPunctuation.UIKeyboardTypeNumberPad - ¿Mostrar solo numbes en el iPad?

¿Hay algo que me falta, o ha sido eliminado del SO del iPad?

¡Gracias por su orientación!

+1

No es que fue eliminado, pero más bien que nunca estuvo allí en primer lugar. Tienes que crear tu propio teclado para hacer esto. Ver: [¿Cómo recupero las pulsaciones de teclado desde un teclado personalizado en una aplicación iOS?] (Http://stackoverflow.com/a/13351686/937822) – lnafziger

Respuesta

13

creo que esto no se admite actualmente en iPhoneOS 3.2 en el iPad

citar el UITextInputTraits encabezado del archivo:

// 
// 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). 
// 
+1

Pero lo he visto en el iPad dentro de un popover. ¿Cómo lo hicieron? – David

+3

Probablemente lo hayan implementado ellos mismos. – ceejayoz

2

Sé que esta pregunta ha estado inactiva durante bastante tiempo, pero esto podría ayudar a alguien por ahí.

Puedes probar implementando este https://github.com/azu/NumericKeypad. El codificador implementa su propio teclado numérico comprar la subclasificación de la UITextField

+0

Gracias, eso está bien – Justin

8

añadir UITextFieldDelegate en el archivo de cabecera (.h)

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

continuación, agregue este método

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

NSString *validRegEx [email protected]"^[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; 
} 
+1

Esto no responde a lo que la pregunta (para mostrar solo los números en un iPad), sino que usa el teclado predeterminado (con letras, etc.) y restringe la entrada para que solo se permitan números. – lnafziger

Cuestiones relacionadas