Toggle UITextAutoCorrectionType WHEN UITextField is being edited

I want to enable / disable automatic correction based on content in a textbox.

For example, if the user enters a phrase like "Machine", I want to turn on auto-correction (for the rest of the words she types), but if I feel the beginning - say - a web address like "www.mach .." I want to turn off auto-correction.

I tried to do this when getting the UITextFieldTextDidChangeNotification by switching the autoCorrectionType to the textbox based on the entered content. Although the actual value of this property in the text box is changed (verified with NSLog), the actual behavior of the correction is not affected. So if auto-correction was enabled at the start of an edit session, it still persists even after I set the textbox to UITextAutoCorrectionTypeNo. Therefore, "www.foogle ..." is corrected to "www.google ..", which may not always be desirable in my book.

So has anyone found a way to enable / disable automatic correction on the fly (while editing) in a textbox?

Thanks.

+2


a source to share


2 answers


The UITextView needs to reload something internally, which it doesn't do automatically, so we have to start it externally. I found a way to retire and be first responder again:

[textView resignFirstResponder];
// UITextAutoCorrectionType change
[textView becomeFirstResponder];

      



It works. Remember to restore the selected range.

Raphael

+6


a source


I was able to run [textField reloadInputViews]

after setting the auto correct type.



Remember that this resets the keyboard state. If you were looking at characters (instead of letters), after the call, the reloadInputViews

keyboard will be reset to a letter.

+2


a source







All Articles