Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing characters with button

Tags:

iphone

i create a custom backspace button but my problem is my back button works great in order to delete character from middle of words but just remove 1 character after that (removing letters) , comes back to the end of line it means doesn't stay where the cursor is, here is my code :

        NSRange deleteRange = textPad.selectedRange;

        if (deleteRange.length >0)
        textPad.text = [textPad.text stringByReplacingCharactersInRange:deleteRange withString:@""];


        else

            if (deleteRange.location > 0)
            textPad.text =  [textPad.text  stringByReplacingCharactersInRange:NSMakeRange(deleteRange.location-1,1) 
 withString:@""];
like image 840
Mc.Lover Avatar asked Oct 28 '10 19:10

Mc.Lover


1 Answers

i fixed it : just add this codes :

deleteRange.location--;
deleteRange.length = 0;
textPad.selectedRange = deleteRange;
like image 197
Mc.Lover Avatar answered Oct 23 '22 05:10

Mc.Lover