0

I've used two secure textfields(new password & confirm password), When I tried to clear a single character in a textField using backspace. It clears the whole text. How to fix this issue

Vikraman R
  • 13
  • 6

1 Answers1

1

You need to detect backspace tapped and then remove last element from string with using textField delegate

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let  char = string.cString(using: String.Encoding.utf8)!
let isBackSpace = strcmp(char, "\\b")

if (isBackSpace == -92) {
     print("Backspace pressed")
}
return true
}

Dont forget to add UITextFieldDelegate to your ViewController

Omer Tekbiyik
  • 4,255
  • 1
  • 15
  • 27