Reputation: 47
I have been having issues regarding having a tap event on my textfield. I have tried almost everything. Almost. From including the textfield delegate to calling it, to making the textfield into an action, all the way to adding UIGestureRecognizers and using the made selector in a function form.
my textfield is also in another swift file as it is inside a custom cell. I would very much appreciate if anyone could help me on this issue. I have been searching for a while now.
There isn't really any reason to show code since all that I'd like is to have some code execute once the user is inside the textview and typing. I know that the UITextViewDelegate handles this wonderfully, but it isn't working for me. The code is being done inside the custom cell file. I'm doing something incorrect I believe. I have added the
func textFieldDidBeginEditing(textField: UITextField) {
}
but I have no idea on how to connect my textview to that function. Also, when I use the
var text_view_tap_gesture = UITapGestureRecognizer(target: self, action: Selector("tapped:"))
textfield.addGestureRecognizer(text_view_tap_gesture)
it doesn't register anything whatsoever.
Any help would be very much appreciated. Thanks.
Upvotes: 0
Views: 430
Reputation: 5039
Here's how you can add a target for the "EditingDidBegin" control event.
self.textField.addTarget(self, action: "handleTap:" forControlEvents: .EditingDidBegin)
Upvotes: 2