I'm trying to make a show/hide password textfield toggle in Objective-C, but I'm having an issue with secure text entry.
I've seen some answers to this question, (this and this), but I can't get myself around the problem.
So, I have a button that interacts with the text field and toggles secure text entry.
- (IBAction)showHidePassword:(id)sender {
UIButton *btn = sender;
if (self.passTextField.secureTextEntry == YES) {
self.passTextField.secureTextEntry = NO;
[self.toggleBTN setImage:[UIImage systemImageNamed:@"eye.fill"] forState:UIControlStateNormal];
} else {
self.passTextField.secureTextEntry = YES;
[self.toggleBTN setImage:[UIImage systemImageNamed:@"eye"] forState:UIControlStateNormal];
}
}
The problem is that when the user toggles from show to hide again, the text disappears and has to start again. This seems to be the default behavior in iOS.
I don't know if there is a way around this using button actions and not functions, or maybe I could hide the text with another property instead of secure text.