-3
A
回答
1
應實現協議UITextViewDelegate方法
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
,只是得到範圍 試試這個有一個日誌文本(這是在的情況下空它不是一個替代而是一種新的輸入)
- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSLog(@"deleting this string: |%@|", [textView.text substringWithRange:range]);
return YES;
}
PS
記得設置你的類作爲您的UITextView的代表
+0
對不起,我不明白我只是想檢測哪些字符在鍵盤背部空間刪除... '文字'返回新的替換字符右未刪除字符.. –
+0
好吧,對不起...我改變了我的答案... – meronix
+0
哎那真棒人爲我工作感謝您的幫助.. –
-1
這就是你想要的。該方法檢測到一個字符被刪除,並將其打印到控制檯。
@interface ViewController()<UITextFieldDelegate>
{
UITextField *textField;
NSString *currentText;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, self.view.frame.size.width-40, 30)];
[textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];
textField.delegate = self;
textField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:textField];
}
-(void)textChanged:(UITextField *)sender{
if (!currentText) {
currentText = sender.text;
}
if (![currentText isEqualToString:sender.text]) {
//The text that is in the textField at the moment is shorter than it was the last time the textfield was editted... This shows that a backspace was pressed
if (currentText.length > sender.text.length) {
NSLog(@"Character: %@", [currentText substringFromIndex:sender.text.length]);
}
}
currentText = sender.text;
}
@end
相關問題
- 1. 顯示軟鍵盤時的後退鍵的Android鍵事件?
- 2. Android:區分屏幕上的後退鍵和物理鍵盤後退鍵
- 3. 鍵盤單擊多個事件
- 4. 點擊鍵盤事件
- 5. 之前的UITextView委託事件稱爲鍵盤事件
- 6. 按鈕單擊後沒有觸發ActionScript 3鍵盤事件
- 7. 鍵盤,方向和UITextView
- 8. 生成後退鍵事件
- 9. Android TabActivity後退鍵事件
- 10. 鍵盤事件上的coco2d(python)和pyglet
- 11. 後退按鈕事件軟鍵盤隱藏事件後,不會觸發
- 12. Opera的右鍵單擊會禁用鍵盤事件
- 13. VueJS中的右鍵單擊和右鍵單擊事件
- 14. 檢測鍵盤空間點擊
- 15. 鍵盤打開後點擊空白
- 16. jQuery鍵盤事件需要在擊鍵之間暫停
- 17. jQuery的包括事件點擊鍵盤
- 18. 鍵盤消除了後退按鈕事件 - Android
- 19. 在statechange事件中區分後退/前進單擊和History.pushState/replaceState
- 20. 鍵盤上的空間按鈕替換UITextview中的字符 - iOS(Obj-C)
- 21. 防止在UITextView上點擊事件
- 22. 如何禁用UITextView上的鍵盤?
- 23. 鍵盤上的點擊事件:向上,向下,向左,向右
- 24. 按鈕上的onClick事件和'空格鍵'按鍵事件
- 25. UICatalog和鍵盤事件
- 26. Android:PopupWindow填充鍵盤上方的空間
- 27. 單擊鍵盤輸入上的指定事件:向上,向下,向左,向右
- 28. 在IE上右鍵單擊事件
- 29. 上下文ActionBar隱藏,當我點擊硬件後退,鍵盤輸出
- 30. 鍵盤事件
我正在尋找解決方案,但沒有發現任何所以如果您有任何請幫助.. –