ioscocoa-touchuitextviewautocorrect

Can you programmatically accept a spelling correction in UITextView?


I have a button that inserts a character into a UITextView. I want this button to behave as the spacebar button does; I want the pending autocorrect suggestion to be accepted upon pressing it.

Can this be done? If so, how? Thanks!


Solution

  • There isn't any API to interact directly with autocorrect. However, there is a bit of a hack I ran across not long ago: if you resign the responder, the currently displayed autocorrect will be accepted. So, you may be able to get away with resigning the first responder and then assigning it again:

    [myTextView resignFirstResponder];
    [myTextView becomeFirstResponder];