1
\\Action 1
textfield.addTarget(self, action: #selector(self.didChangeText(textField:)), for: .editingChanged)
textfield.tag = self.numarr

\\Action 2
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
textfield.addGestureRecognizer(tap)
textfield.isUserInteractionEnabled = true

Both functions fire but individually. When together the gesture function fires but the 2nd (addTarget) doesn't fire. Any fixes?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Khan Luke
  • 168
  • 1
  • 13

1 Answers1

2

Tap gesture is not suitable for UITextField you may use textDidBeginEditing. Still if you want a tap effect you may need to use some transparent overlay using UIImageView or UIButton. UITextField has delegate methods, you might want to consider implementing those. Or just add action event to your textfield.

textField.addTarget(self, action: #selector(self.textDidBeginEditing(sender:)), for: UIControlEvents.editingDidBegin)

Then implement this:

func textDidBeginEditing(sender:UITextField) -> Void
{
   // handle begin editing event
} 

Similarly you can place a transparent button and inside the action of that button you can place your desired code and also hide the button from the view till the control change from UITextField.

Khan Luke
  • 168
  • 1
  • 13
Saad Chaudhry
  • 1,392
  • 23
  • 37