且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UITextField如何检查是否按下了删除键

更新时间:2023-12-03 07:57:28

您可以在此方法后获取应该位于文本字段中的字符串:

You can get the string that is supposed to be in text field after this method:

NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];

那个 neString 你可能会用'用于搜索数据库。

And that neString you probably can use 'as is' for searching the database.

如果您只是想在用户删除textField中的某些字符时获取该事件 - 那么您可以通过以下方式进行检查:

If you just want to get the event when user deletes some characters in textField - then you can check it the following way:

if ([string length] == 0 && range.length > 0)
  //Some characters deleted