Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In iOS, how do I auto-correct the last word upon submit?

On my iOS app's chat screen, words get auto-corrected after the user enters a space. But the last word does not get auto-corrected when the user taps Send. How can I get the suggested word to replace the misspelled word when the user taps Send?

like image 926
Jesse Wilson Avatar asked Mar 30 '13 01:03

Jesse Wilson


2 Answers

The last solution forces you to hide your keyboard. I found a solution that autocorrects the last word without resigning the keyboard by adding a space at the end before submitting:

// This will force the autocompletion to take effect
text = [NSString stringWithFormat:@"%@ ", text];

// Remove the last character afterwards
text = [text substringToIndex:[text length]-1];
like image 124
mengto Avatar answered Oct 26 '22 12:10

mengto


If you call resignFirstResponder on your text field as the first action after pressing send, it will accept the correction before sending.

- (IBAction)sendButtonPressed:(id)sender
{
    [textField resignFirstResponder];
    // Send the textfield's text
}
like image 34
nevan king Avatar answered Oct 26 '22 11:10

nevan king