自定义键盘iPhone,UITextView中的退格按钮出现问题 [英] Custom keyboard iphone , having problem with backspace button in UITextView

查看:41
本文介绍了自定义键盘iPhone,UITextView中的退格按钮出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查此代码(我的自定义键盘"):

Check this code (My Custom Keyboard):

-(IBAction) updateTextBackSpace:(id)sender
{
    if([txtview.text length]>0)
    {
        NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];
        [txtview setText:deletedLastCharString];
    }
    else
    {
        return nil;
    }
}  

问题是我不知道如何更改此代码.我可以删除光标处任何给定行中的任何文本,退格键从行尾开始删除.我应该能够从光标位置擦除(退格).

The thing is that I can't figure out how to change this code so that. I can erase any text in any give line at the cursor, the backspace starts to erase from end of the line. I should be able to erase(backspace) from the cursor location.

推荐答案

替换此

NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];

NSRange range  = [txtview selectedRange];
NSString *deletedLastCharString = [txtview.text substringToIndex:([range.location]-1)];

这篇关于自定义键盘iPhone,UITextView中的退格按钮出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆