Jesse Wilson
Jesse Wilson

Reputation: 71

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?

Upvotes: 7

Views: 1717

Answers (2)

mengto
mengto

Reputation: 689

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];

Upvotes: 4

nevan king
nevan king

Reputation: 113747

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
}

Upvotes: 3

Related Questions