ios - UITextFieldDelegate "shouldChangeTextInRange"未调用

标签 ios objective-c

我有一个UITextField我想使用正则表达式。我想使用

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

来自UITextFieldDelegate的方法.

在我的 XIB 文件中,委托(delegate)被设置为文件的所有者。在 .h 文件中设置协议(protocol) UIViewController<UITextFieldDelegate>

textFieldDidEndEditingtextFieldDidBeginEditing工作正常。

shouldChangeTextInRange没有被调用,但是为什么呢?

最诚挚的问候

最佳答案

这是因为您正在 UITextView 而不是 UITextField 上实现委托(delegate)。您应该实现:

- (BOOL)textField:(UITextField *)iTextField shouldChangeCharactersInRange:(NSRange)iRange replacementString:(NSString *)iString

关于ios - UITextFieldDelegate "shouldChangeTextInRange"未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33275712/

相关文章:

ios - 如何从返回类型为 id 的方法中返回任何内容

android - 应用程序如何在没有服务器的情况下代表用户访问 OAuth 服务(例如 Dropbox)?

ios - 替换 GoogleService-Info.plist 是否足以让其他人的应用程序使用我的包标识符?

objective-c - 使用 addSubview 动态添加 UITextField 的 UITableViewCell - 如何在 'return' 击中键盘时获取 UITextField 值

ios - 如何判断字典键是 NSArray 还是 Bool 类型

objective-c - 返回 C 结构数组

ios - 如何在 UILabel 上为下划线创建属性?

ios - 如何保证XMPP消息发送到openfire服务器?

ios - CLLocationManagerDelegate 方法未更新

iphone - 检测 iOS 5 上的铃声(静音按钮)位置?