【发布时间】:2010-10-04 13:50:27
【问题描述】:
我在自定义 iPhone 键盘上的自定义退格和输入按钮有问题,
退格键:我的代码只是删除了行尾的字符,而不是光标位置的字符。
if ([textView.text length]>0) textView.text = [textView.text substringToIndex:([textView.text length]-1)];
阅读了这个问题Custom keyboard iphone , having problem with backspace button in UITextView,但没有解决我的问题。
回车:我有同样的问题,比如退格回车按钮只是在句子末尾插入新行而不是从光标位置。
textView.text = [NSString stringWithFormat:@"%@\n", textView.text];
我应该如何更改我的代码才能正常工作?谢谢你
编辑: //退格键代码:
NSRange deleteRange = textPad.selectedRange;
deleteRange.length -= 1;
if ([textPad.text length]>0) textPad.text = [textPad.text stringByReplacingCharactersInRange:deleteRange withString:@""];
【问题讨论】: