Daniele B Daniele B - 1 year ago 179
iOS Question

iOS/Swift: how to detect touch action on a UITextField

I would like to detect the touch action on a UITextField.

It seems the "Touch Up Inside" action is not fired by touching inside the textfield.

Answer Source

It seems "Touch Up Inside" is not enabled for UiTextField, but "Touch Down" works.

So the solution is as follows:

myTextField.addTarget(self, action: "myTargetFunction:", forControlEvents: UIControlEvents.TouchDown)

func myTargetFunction(textField: UITextField) {
    // user touch field
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download