10

UITextField 是否忽略 inputDelegate?使用以下代码:

- (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 不会导致任何更改,并且不会调用委托方法。

4

2 回答 2

0

我遇到了和你一样的问题。经过深入搜索,我发现虽然 UITextInput 协议存在于 iOS 3.2 中,但 UITextView/Field 在 iOS 5 之前没有使用该协议。在 iOS 5 或更高版本中运行您的代码,它应该可以工作。

于 2012-04-05T06:51:37.763 回答
0

在编辑会话开始设置您的委托。

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    [self.myTextfield setInputDelegate:self];
    NSLog(@"Inputdelegate is: %@", self.myTextField.inputDelegate);

    return YES;

}
于 2016-05-27T04:37:06.287 回答