how to insert text at any cursor position in uitextview?

kushalrshah picture kushalrshah · Jan 13, 2012 · Viewed 9.4k times · Source

i want to implement Code by which i can start to insert text at any position of cursor in UITextView in iphone sdk

any idea? thank you in advance..

i refereed this link: iPhone SDK: How to create a UITextView that inserts text where you tap?

But not Getting it.

Answer

ethanhuang13 picture ethanhuang13 · Mar 27, 2014

Dan's answer is manually changing the text. It's not playing well with UITextView's UndoManager.

Actually it's very easy to insert text with UITextInput protocol API, which is supported by UITextView and UITextField.

[textView replaceRange:textView.selectedTextRange withText:insertingString];

Note: It's selectedTextRange in UITextInput protocol, rather than selectedRange