本文介绍了UITextField忽略inputDelegate吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UITextField是否忽略inputDelegate?使用以下代码:
Does UITextField ignore the inputDelegate? Using the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.textField.inputDelegate = self;
NSLog(@"textField: %@", self.textField);
NSLog(@"delegate: %@", self.textField.inputDelegate);
}
我得到以下输出:
2012-03-26 20:43:49.560 InputTest[33617:f803] textField: <UITextField: 0x6c093a0; frame = (20 20; 280 31); text = ''; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x6c094d0>>
2012-03-26 20:43:49.561 InputTest[33617:f803] delegate: (null)
它可以正常运行,没有警告或异常,并且委托属性也可以正常运行.但是设置inputDelegate不会导致更改,并且不会调用委托方法.
It runs just fine, without warning or exception, and the delegate property works just fine. But setting the inputDelegate causes no change and the delegate methods are not called.
推荐答案
在编辑会话开始后 设置您的委托.
Set your delegate after the editing session has begun.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
[self.myTextfield setInputDelegate:self];
NSLog(@"Inputdelegate is: %@", self.myTextField.inputDelegate);
return YES;
}
这篇关于UITextField忽略inputDelegate吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!