1

Tengo un UITextField en una pantalla inicial y quiero que aparezca el teclado subido nada mas empezar la vista sin hacer falta pulsar dentro de la caja del UITextField. Cuando pulse return quiero que me haga una comprobación del texto tecleado con un string si es el mismo el teclado puede bajar o quedarse subido. Si el texto no es el mismo el teclado debe permanecer subido, y permitirme volver a introducir otro texto. También deseo deshabilitar la tecla de esconder teclado.

Actualmente tengo este código:

dentro del ViewDidLoad: [self.textField becomeFirstResponder]

'- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}'

Para comprobar el texto lo hago dentro de un -(IBAction)didEndPass y hago una cosa u otra.

1 respuesta 1

3

Para que el teclado aparezca subido debes indicárselo haciendo que el textField sea BecomeFirstResponder. Imagino que tienes una propiedad apuntando a ese textField, con su delegado asignado. Tendras algo como esto:

@property (strong, nonatomic) UITextField *textField;

En el viewWillAppear, le indicas que sea el firstResponder, entonces se abrirá el teclado

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.textField becomeFirstResponder];
}

Para saber cuando le dan al Enter, hay que modificar un poco la función que tienes escrita

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if ( textField.text == "xxxxxxx" ) {
        [textField resignFirstResponder];
    } else {
        #mostrar el mensaje que quieras
    }
    return YES;
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.