I have written my own function to scroll text fields up when the keyboard shows up. In order to dismiss the keyboard by tapping away from the text field, I've created a UITapGestureRecognizer
that takes care of resigning first responder on the text field when tapping away.
Now I've also created an autocomplete for the textfield that creates a UITableView
just below the text field and populates it with items as the user enters text.
However, when selecting one of the entries in the auto completed table, didSelectRowAtIndexPath
does not get called. Instead, it seems that the tap gesture recognizer is getting called and just resigns first responder.
I'm guessing there's some way to tell the tap gesture recognizer to keep passing the tap message on down to the UITableView
, but I can't figure out what it is. Any help would be very appreciated.
My case was different including a uisearchbar and uitableview on self.view. I wanted to dismiss uisearchbar keyboard by touching on the view.
On UISearchBar Delegate Methods:
When user touches on self.view:
ISSUE: In my case, the issue was that I originally placed a button in each collectionView cell and set the constraints to fill the cell, so that when the cell was clicked it would click the button, however the buttons function was empty so nothing was appearing to be happening.
FIX: I fixed this by removing the button from the collection view cell.
Set
cancelsTouchesInView
of your recognizer to false. Otherwise, it "consumes" the touch for itself, and does not pass it on to the table view. That's why the selection event never happens.for example in
swift
And for Swift (based on answer from @Jason):
Here is my solution, which ties the recognizer's shouldReceiveTouch directly to whether the keyboard is showing.
In your tap gesture recognizer delegate:
And the
PFXKeyboardStateListener.h
:And the
PFXKeyboardStateListener.m
:You may want to update the singleton pattern of the keyboard listener, I haven't gotten to it yet. Hope this works for everyone else as well as it works for me. ^^
Ok, finally found it after some searching through gesture recognizer docs.
The solution was to implement
UIGestureRecognizerDelegate
and add the following:That took care of it. Hopefully this will help others as well.