2

I have a UITextField instance with secureTextEntry = YES. When the field first gains focus any keypress will clear the field, as appears to be standard behavior on iOS.

As far as I can tell, UIControlEventEditingChanged is not triggered. I have also tried subscribing to UIControlEventAllEditingEvents but it appears not to be triggered. This is causing an issue for me since I'm relying on knowing when the field is edited to set the enabled attribute of a UIButton.

Is there an event which is fired when the field is cleared in this way?

They context around my issue can be seen in this GitHub issue.

Paul Young
  • 1,489
  • 1
  • 15
  • 34

3 Answers3

1

You can use the UITextField's delegate:

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:text];
    [self performSelector:@selector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (BOOL)textFieldShouldClear:(UITextField *)textField {
    [self performSelector:@selector(updateButton) withObject:nil afterDelay:0.1];
    return YES;
}

- (void) updateButton {
    someButton.enabled = NO;
}
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

If I add an action for UIControlEventAllEvents, the method does not get called when the text field is cleared in this way which confirms that no event is triggered.

Paul Young
  • 1,489
  • 1
  • 15
  • 34
  • This was receiving flags for reading like a comment more than an answer. I've undeleted it, but see if you can clarify it beyond a simple remark "which confirms that no event is triggered", which can be easily missed. – BoltClock Sep 04 '13 at 19:09
0

hi you can use the following Method:

 - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        [self performSelector:@selector(MakeButtonEnabled:) withObject:nil afterDelay:0.2];
        return YES;
    }

- (void) MakeButtonEnabled:(id)sender {
    UIButton *yourButton=(UIBUtton*) sender;
    yourBUtton.enabled = NO;
}

hope this will help you.

hpp
  • 619
  • 3
  • 13