Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Add Tap Gesture to UITextField

I have problem with add a Tap Gesture to my UITextField. Below code:

@IBAction func hanldeTap(recognizer: UITapGestureRecognizer) {
    println("works")
}

This action is associated with Tap Gesture Recognizer. In my TextField I have defined gestureRecognizer in OutletCollections. In my guess it should works. In described configuration gesture works e.x. for button or custom view.

Can you tell my what could go wrong and how can I fix this?

like image 868
LakaLe_ Avatar asked Sep 04 '14 22:09

LakaLe_


1 Answers

UITextField has delegate methods, you might want to consider implementing those. Or just add action event to your textfield.

For example in viewDidLoad

textField.addTarget(self, action:Selector("textDidBeginEditing"), forControlEvents: UIControlEvents.EditingDidBegin)

Then implement this:

func textDidBeginEditing(sender:UITextField) -> Void
{
   // handle begin editing event
} 
like image 93
Allan Macatingrao Avatar answered Sep 19 '22 00:09

Allan Macatingrao