嘿伙计检查此代码(我的自定义键盘):
-(IBAction) updateTextBackSpace:(id)sender
{
if([txtview.text length]>0)
{
NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];
[txtview setText:deletedLastCharString];
}
else
{
return nil;
}
}
问题是我无法弄清楚如何更改此代码,以便我可以删除光标处任何给定行中的任何文本,退格开始从行尾删除。我应该能够从光标位置擦除(退格)请帮助
答案 0 :(得分:3)
替换此
NSString *deletedLastCharString = [txtview.text substringToIndex:([txtview.text length]-1)];
带
NSRange range = [txtview selectedRange];
NSString *deletedLastCharString = [txtview.text substringToIndex:([range.location]-1)];