Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I want to turn auto-correction on/off based on the content in the text field.
For example, if the user is typing a phrase like "Machine tools" I want auto-correction to be on (for the rest of the words she's gonna type) but if I sense the beginnings of - say - a web address like "www.mach.." I want to turn auto-correction off.
I tried doing this on receiving the UITextFieldTextDidChangeNotification, by toggling autoCorrectionType on the textfield based on the content typed. While the actual value of this property on the text field changes (verified this with an NSLog) the actual correction behaviour does not get affected. So if auto-correction was on at the beginning of the editing session, it continues to be so even AFTER I have set the text field to UITextAutoCorrectionTypeNo. So "www.foogle..." gets corrected to "www.google.." which may not always be desirable in my book.
So has anyone found a way to enable/disable auto-correction on the fly (when editing) in a text field?
Thanks.
–
UITextView has to reload something internally which it doesn't do automatically, so we have to trigger it from the outside. A way I found is to resign and become first responder again:
[textView resignFirstResponder];
// UITextAutoCorrectionType change
[textView becomeFirstResponder];
This works. Remember to restore the selected range.
Raphael
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.