1

I have a UI that includes a password entry field and a show/hide button. A tester has pointed out the following inconsistent behaviour.

If the password is hidden and half typed in (e.g. "abc") and the user hits the toggle button to show the password and continues typing then the new characters (e.g. "def") are added to the end of the initial entry (making "abcdef"). All well and good.

However, if the password is shown and half typed in (e.g. "abc") and the user hits the toggle button to hide the password and continues typing then the new characters (e.g. "def") replace the initial entry (making "def"). So the show/hide toggle not only shows or hides the text but also changes the behaviour of the UITextField (append / clear and start over) when the next character is entered.

Why is this happening?

fpg1503
  • 7,492
  • 6
  • 29
  • 49
lakshmi
  • 31
  • 9

2 Answers2

1

Correct it is normal behaviour of UITextField and you can fix this using:

textField.clearsOnBeginEditing = NO;

Or in Swift:

textField.clearsOnBeginEditing = false

But it will not work if you use secure text for password.

See One of the answer:

Secure UITextField Answer

Community
  • 1
  • 1
Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
0

you can realization the effect you want by change your mind.

you can init a NSString *pwd to store the user's password, when user del or replace password , you change your pwd value, make sure your pwd always equal to user's typed password.

when user click the toggle button,you show the pwd value on the textfield.

Ezatu.
  • 9
  • 1