iPhone: Issue disabling Auto-Cap/autocorrect on a UITextField
Objective - 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
}
You're setting autocorrectionType
to FALSE
as if it were a BOOL
, but it actually has type UITextAutocorrectionType
. So FALSE
is being interpreted as UITextAutocorrectionTypeDefault
, which means that autocorrection is probably enabled.
I bet it found the name "Phil" in your address book and is autocorrecting the capitalization to match.