I’m trying to insert a text into a UITextField. But by insert, I mean replacing the character at cursor position with the new one (insert button’s functionality on windows).
If I manually replace the incoming string and do setText (with NO returned to shouldChangeCharactersInRange method), the cursor moves to the end of textField.
You can replace the text as you have done previously and restore the position of your caret. Note that this can only be done with
UITextViewrather thanUITextField(that would require a lot more unjustified work, unless you absolutely have to useUITextField):You have to note that it’s a good idea to check the validity of
selectionRangevariable for new text – make sure that cursor position isn’t greater than the new text length.