UITextField ignoring inputDelegate?
Asked Answered
B

2

10

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);
}

I get the following output:

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)

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.

Boisterous answered 27/3, 2012 at 3:48 Comment(2)
Have you declared the VC as a <UITextInputDelegate> ? I imagine you would have, or else seen a compiler warning.Vesting
Hmm. I just tried it in a random view controller, even with the protocol warning, and my code - duplicate of yours - worked fine.Vesting
C
0

I have the same problem as you are facing. upon deep searching i found out that, though UITextInput Protocol was there in iOS 3.2 but UITextView/Field didn't make use of that protocol before iOS 5. Run your code in iOS 5 or later and it should work.

Calix answered 5/4, 2012 at 6:51 Comment(0)
M
0

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;

}
Mortify answered 27/5, 2016 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.