Nam
Nam

Reputation: 1876

Detect UITextField Secure Text Entry overwritten text

When using Secure Text Entry in a UITextField the text is overwritten if I have entered a text, gone to another text field and coming back and start writing without pressing back.

Now, Im using the following to keep track of the entered text:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
}

But in the case above, the event doesnt track that the textfield has been cleared thus I cannot always rely on the string text

Any good tips?

Upvotes: 0

Views: 739

Answers (2)

Soorej Babu
Soorej Babu

Reputation: 368

i can tell you an easy way to do it in the xcode itself.

Select <code>Clear when editing begins</code> checkbox

Select Clear when editing begins checkbox

Select <code>Secure</code> checkbox

Select Secure checkbox

Upvotes: 0

Nam
Nam

Reputation: 1876

Okay, I simply changed the logic as track textfield changes with this event instead:

[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];

textFieldDidChangewill be called each time the text changes.

Upvotes: 4

Related Questions