我有一个UITextField
我想使用正则表达式。我想使用
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
来自UITextFieldDelegate
的方法.
在我的 XIB 文件中,委托(delegate)被设置为文件的所有者。在 .h 文件中设置协议(protocol)
UIViewController<UITextFieldDelegate>
textFieldDidEndEditing
和textFieldDidBeginEditing
工作正常。
shouldChangeTextInRange
没有被调用,但是为什么呢?
最诚挚的问候
最佳答案
这是因为您正在 UITextView
而不是 UITextField
上实现委托(delegate)。您应该实现:
- (BOOL)textField:(UITextField *)iTextField shouldChangeCharactersInRange:(NSRange)iRange replacementString:(NSString *)iString
关于ios - UITextFieldDelegate "shouldChangeTextInRange"未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33275712/