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)
它运行得很好,没有警告或异常,委托(delegate)属性工作得很好。但是设置 inputDelegate 不会导致任何变化,也不会调用委托(delegate)方法。
最佳答案
我遇到了和你一样的问题。 经过深入搜索,我发现,虽然 UITextInput 协议(protocol)在 iOS 3.2 中存在,但 UITextView/Field 在 iOS 5 之前没有使用该协议(protocol)。 在 iOS 5 或更高版本中运行您的代码,它应该可以工作。
关于iphone - UITextField 忽略 inputDelegate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9883137/