0

I have created an action that changes the color of UITextField. But when I tap on the textfield it changes color but the keyboard does not appear. The keyboard appears only on second tap. Is this an issue of first responder? I'm new to Swift programming.

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    textfield1.addTarget(
        self,
        action: #selector(textfield1.handleFrontTap(_:)),
        forControlEvents: UIControlEvents.EditingDidBegin
    )
}

func handleFrontTap(sender: UITextField) -> Void {
    print("tap working")
    setColor()
    self.textfield1.endEditing(true)

}
Evgeny Karkan
  • 8,782
  • 2
  • 32
  • 38

2 Answers2

1

Try to change control event from EditingDidBegin to TouchUpInside

And remove this line of code:

self.textfield1.endEditing(true)
Evgeny Karkan
  • 8,782
  • 2
  • 32
  • 38
0

Don't you think it's your self.textfield1.endEditing(true) that's cancelling the keyboard showing?

Happiehappie
  • 1,084
  • 2
  • 13
  • 26