2010-03-19 14 views
46

Por alguna razón, aunque desactivo el auto-cap y la autocorrección de mi UITextField, aún está escribiendo en mayúscula la primera letra de mi entrada.iPhone: Problema que deshabilita Auto-Cap/autocorrect en un UITextField

Aquí está el código:

UITextField* textField = [[[UITextField alloc] initWithFrame:CGRectMake(90.0, 10.0, 213.0, 25.0)] autorelease]; 
[textField setClearButtonMode:UITextFieldViewModeWhileEditing]; 
textField.returnKeyType = UIReturnKeyGo; 
textField.autocorrectionType = FALSE; 
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; 
textField.delegate = self; 
if (inputFieldType == Email) { 
    label.text = @"Email:"; 
    textField.keyboardType = UIKeyboardTypeEmailAddress; 
    emailTextField = textField; 
    textField.placeholder = @"Email Address"; 
} else { // password 
    textField.secureTextEntry = TRUE; 
    label.text = @"Password:"; 
    if (inputFieldType == Password){ 
     textField.placeholder = @"Password"; 
     passwordTextField = textField; 
    } 
    if (inputFieldType == ConfirmPassword){ 
     textField.placeholder = @"Confirm Password"; 
     confirmPasswordTextField = textField; 
    } 

} 

Ver Captura: alt text http://grab.by/39WE

Respuesta

60

está configurando autocorrectionType-FALSE como si se tratara de un BOOL, pero en realidad tiene escribir UITextAutocorrectionType. Por lo tanto, FALSE se interpreta como UITextAutocorrectionTypeDefault, lo que significa que la autocorrección probablemente esté habilitada.

Apuesto a que encontró el nombre "Phil" en su libreta de direcciones y está autocorregiendo las mayúsculas para que coincidan.

+1

Ja! Yo tuve el problema contrario. La corrección automática se deshabilitó correctamente, pero estaba configurando las mayúsculas automáticas en FALSO - ¡oh! – philsquared

30

Objetivo - C

-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 
    textField.autocorrectionType = FALSE; // or use UITextAutocorrectionTypeNo 
    textField.autocapitalizationType = UITextAutocapitalizationTypeNone; 

} 

Swift

func textFieldDidBeginEditing(textfield : UITextField) 
{ 
    textField.autocorrectionType = .No 
    textField.autocapitalizationType = .None 
    textField.spellCheckingType = .No 
} 

Swift3

func textFieldDidBeginEditing(_ textField : UITextField) 
{ 
    textField.autocorrectionType = .no 
    textField.autocapitalizationType = .none 
    textField.spellCheckingType = .no 
} 
+0

Hola Anbu, Cómo podemos habilitar la misma opción (textField.autocorrectionType = FALSE; // o usar UITextAutocorrectionTypeNo) para NSTextfield (aplicación Mac). ¿Alguna idea? – Surezz

7
yourTextFieldName.autocorrectionType = UITextAutocorrectionTypeNo; 
yourTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeNone; 
2

Swift 2:

textField.autocorrectionType = .No 
textField.autocapitalizationType = .None 
+1

Agregue una descripción de la solución que está proponiendo. –

Cuestiones relacionadas