Pregunta

Normal UITextField muestra una UIKeyboard que incluye alfa+Numberic+extras

Pero necesito alfa sólo...

Necesito esto porque si el usuario introduce algo como -- Un bad

tiene un char ' -- que está afectando a mi consulta .

Cómo podemos poner sólo alphabetic UIKeyboard para el usuario?

¿Fue útil?

Solución

Este post SO responde a su pregunta: UIkeyboard escriba

Otros consejos

Creo. Tengo la respuesta.

En el archivo UIViewController .h añadir delegate<UITextfieldDelegate>

Ahora agregue el código siguiente a .m archivo

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

    for (int i = 0; i < [textEntered length]; i++) {
        unichar c = [textEntered characterAtIndex:i];
        if (![myCharSet characterIsMember:c]) {
           return NO;
        }
    }
    return YES;

}

Debe usar al mismo hago a continuación;

- (BOOL)textField:(UITextField *)field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)characters
{
    NSMutableCharacterSet *filteredChars = [NSMutableCharacterSet letterCharacterSet];
    [filteredChars formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]];
    NSCharacterSet *blockedCharSet = [filteredChars invertedSet];
    if (([string rangeOfCharacterFromSet:blockedCharSet].location == NSNotFound)) {
          return YES;
    }
    return NO;
}

En lugar de desactivar o no permitir al usuario añadir '(apostorpe) Uso siguiente código, que le permitirá insertar' (apostorpe)

[textEntered stringByReplacingOccurrencesOfString:@" ' " withString:@" ' '"];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top