4

I have created a custom subclass of UITextField, CustomTextView.

  • I created a

    private var tapGesture = UITapGestureRecognizer()
    

    in the customTextView class

  • In the initInView, I have the following code

    tapGesture.addTarget(self, action: "tapTextField:")
    self.addGestureRecognizer(tapGestureRecognizer)
    
  • CustomTextView implements UIGestureRecognizerDelgate

  • CustomTextView has a private func named tapTextField

Now when I use iOS simulator and click on the text field, the function tapTextField never gets called.

What am I missing here? I saw similar posts but none of them answer my question. I could not comment on those as I don't have reputation yet. So asking as a new question.

PS: Does this have to do with firstResponder being set? This is someone else's code I am working on, so I might have missed something. Let me know what I should look for

Related stack overflow questions:

Community
  • 1
  • 1
shrutim
  • 1,058
  • 2
  • 12
  • 21
  • have you set the property `isUserInteractionEnabled` ? – Saheb Singh May 25 '15 at 01:27
  • I presume that the isUserInteractionEnabled is set to true by default as this is a UITextView that I am able to interact with. But I still set it to true explicitly and tried. No luck!! – shrutim May 25 '15 at 01:39

2 Answers2

1

I don't know swift, but try changing this "tapTextField:" to this "tapTextField" and make sure you don't have any arguments/parameters/whatever swift calls them in your "tapTextField" function.

Also, it looks like

self.addGestureRecognizer(tapGestureRecognizer) should be self.addGestureRecognizer(tapGesture)

Elliot Alderson
  • 546
  • 2
  • 17
0

You can try few things to debug the problem.

1> Make sure there is no mistake of tapTextField and tapTextField: i.e. you are adding selector with argument but you have implemented same method without any argument.

2> Make sure no any other transparent view obscuring your custom uitextfield. 3> print po yourTextFieldName in the xcode console to see whether actually your textfield has any gesture recognizer added in it or not.

Hope this helps

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88