Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate the delete key on UITextField?

I'm creating an application on the iPad. I create a custom keyboard using UITextField's inputView property. To insert text at the cursor position, I use the copy & paste method (http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html), which works fine. Now, I want to create the delete key. The code that I'm using is:

if (textField.text.length > 0) {
    textField.text = [textField.text substringToIndex:textField.text.length-1];
}

However, as you may know, it only deletes the last character no matter where the cursor is. Does anyone know a better solution?

Thank you very much!

like image 693
Midori Avatar asked Jun 09 '10 16:06

Midori


1 Answers

Just call [textField deleteBackward]. It takes care of cursor position and highlight for you.

like image 154
GoldenJoe Avatar answered Oct 11 '22 20:10

GoldenJoe