Pergunta

UITextField normal exibe uma UIKeyboard que inclui alfa + Numberic + especiais

Mas eu preciso alfa única ...

Eu preciso isso porque se o usuário entra algo como - A'bad

tem um char '-. Que está afetando minha consulta

Como podemos definir alphabetic única UIKeyboard de usuário?

Foi útil?

Solução

This SO post answers your question: UIkeyboard type

Outras dicas

I think. I got the answer.

In your UIViewController file .h add delegate<UITextfieldDelegate>

Now add following code to .m file

- (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;

}

You should use as i do below;

- (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;
}

Instead of disabling or not allowing user to add '(apostorpe) use following code, it will allow you to insert '(apostorpe)

[textEntered stringByReplacingOccurrencesOfString:@" ' " withString:@" ' '"];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top