开发者

Removing characters with button

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.l开发者_开发百科ength >0)
        textPad.text = [textPad.text stringByReplacingCharactersInRange:deleteRange withString:@""];


        else

            if (deleteRange.location > 0)
            textPad.text =  [textPad.text  stringByReplacingCharactersInRange:NSMakeRange(deleteRange.location-1,1) 
 withString:@""];


i fixed it : just add this codes :

deleteRange.location--;
deleteRange.length = 0;
textPad.selectedRange = deleteRange;


You can solve this problem easily by setting the selectedRange property of the UITextView

    NSRange ran= textView.selectedRange
    //do your deletions
    ran.lenght=0;
  if(ran.location!=0)
    ran.location--;
    textView.selectedRange=ran; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜