1

My iOS app has username & password text fields. The username has specific limitations which are ensured by textField:shouldChangeCharactersInRange:replacementString: which returns NO for invalid resulting strings.

In iOS 11 I observe an issue when 'Password AutoFill' feature is used. In this case delegate method is called, but its result is ignored and text is replaced in any case regardless of returned value.

Is it by design, or bug, or maybe I'm missing something?

Jack
  • 13,571
  • 6
  • 76
  • 98
jesse
  • 650
  • 5
  • 19

1 Answers1

0

Yes it is by design, when you set the text property of an textfield, the delegate method below is not called, that's what it might happen

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool

Neither this method below does help anyhow

 func textFieldDidEndEditing(_ textField: UITextField) -> Bool {

            return true
        }

But you could subclass UITextfield, override text property create an extension for the UITextFieldDelegate with a default method 'textChanged' and implement the 'textChanged' method in the delegate

extension UITextFieldDelegate{

    func textChanged(_ textField:UITextField){
        print("textChanged")
    }

}
class CustomTF: UITextField {

        override var text: String?{
            didSet{
                print("didSet text")
                delegate?.textChanged(self)
            }
        }

    }
teonicel
  • 27
  • 5