【问题标题】:UITextField ignoring inputDelegate?UITextField忽略inputDelegate?
【发布时间】:2012-04-10 14:33:27
【问题描述】:

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

【问题讨论】:

  • 您是否将 VC 声明为 ?我想你会看到,否则会看到编译器警告。
  • 嗯。我只是在随机视图控制器中尝试了它,即使有协议警告,我的代码 - 你的副本 - 工作正常。

标签: iphone ios uitextinput


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2014-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多