Is an event triggered when a UITextField with secureTextEntry = YES is cleared?

607 views Asked by At

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.

3

There are 3 answers

0
Aaron Brager On

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;
}
1
Paul Young On

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.

0
hpp On

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.