I have UIViewController
and UITableView
as child in the view,
what I want to do is when I touch any row I am displaying a view at bottom. I want to hide that view if the user touch any where else then rows or the bottomView.
The problem is when I click on UITableView
it doesn't fires touchesEnded
event.
Now how can I detect touch on UITableView
and distinguish it with row selection event.
Thanks.
I was facing the problem since a long time and didn't got any working solution. Finally I choose to go with a alternative. I know technically this is not the solution but this may help someone looking for the same for sure.
In my case I want to select a row that will show some option after that I touch anywhere on table or View I want to hide those options or do any task except the row selected previously for that I did following:
Set touch events for the view. This will do the task when you touch anywhere on the view except the table view.
TableView's didSelectRowAtIndexPath do following
I know that this is older post and not a good technical solution but this worked for me. I am posting this answer because this may help someone for sure.
Note: The code written here may have spell mistakes because directly typed here. :)
No need to subclass anything, you can add a
UITapGestureRecognizer
to theUITableView
and absorb the gesture or not depending on your criteria.In your viewDidLoad:
Then, implement your action like this for the criteria:
And note that if you just want to simply pick up clicks anywhere on the table, but not on any buttons in cell rows, you need only use the first code fragment above. A typical example is when you have a UITableView and there is also a UISearchBar. You want to eliminate the search bar when the user clicks, scrolls, etc the table view. Code example...
Hope it helps someone.
In your controller class declare a method which removes the bottom view. Something like this:
In Interface Builder, select your view and in the identity inspector in the custom class section, change the class from
UIView
toUIControl
. After that go to the connections inspector and connect the TouchUpInside event to the method declared above. Hope this helps.Try this methods:
Use scrollViewDidEndDragging like alternative of touchesEnded. Hope it helps.
You should forward the touch event to the view's controller. Subclass your tableview control and then override the method:
then , you can do what you want in the controller's touch methods.
I just stumbled onto what may be a solution for your problem. Use this code when you create your table view:
Without setting this to
NO
, the touch events are cancelled as soon as there is even a slight bit of vertical movement in your table view (if you put NSLog statements in your code, you'll see thattouchesCancelled
is called as soon as the table starts scrolling vertically).