iphone - 如果我长时间按退格键,UITextField shouldChangeCharactersInRange 将停止调用

标签 iphone ios uitextfield backspace uitextfielddelegate

如果我在 UITextField 中键入很长的文本,例如:123456789012345678901234567890。

现在,如果我按下退格键并保持按下状态,则会在开头为某些字符调用 shouldChangeCharactersInRange。

但是,当 UITextField 开始快速清除时,shouldChangeCharactersInRange 停止调用。谁能建议我一个解决方案。

最佳答案

您可以为 UITextFieldTextDidChangeNotification 添加观察者,只要文本字段中的文本发生变化,它就会被发布。

[[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(yourMethod:)
     name:UITextFieldTextDidChangeNotification 
     object:yourTextField];

在这种情况下,yourMethod: 方法将始终有效。

关于iphone - 如果我长时间按退格键,UITextField shouldChangeCharactersInRange 将停止调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6355856/

相关文章:

ios - 在原型(prototype) tableView 单元格中滚动的问题

objective-c - 为什么每次按下按钮时 UITextField 不刷新?

iphone - 关闭模态视图 Controller 时,底层 UIScrollView 会调整为全屏

iphone - iPhone 中的数据库连接

ios - 在 Swift 中集成 Amazon Simple Email Services API 时出现问题

swift - 没有使用 Objective-C 选择器声明用于通知 UIKeyboardWillShowNotification 和 UIKeyboardWillHideNotification 的方法

ios - 具有负原点的 UITextField 中的自定义光标

android - 用 OpenCV 识别的完美对象

iphone - iOS 5 : UITableView cells are not scrolling smooth

ios - 如何在iOS中实现登录屏幕(附截图)