iphoneuitableviewuiviewcontrollertouches

Touch events on UITableView?


I have UIViewControllerand 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.


Solution

  • 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:

    1. Set touch events for the view. This will do the task when you touch anywhere on the view except the table view.

    2. TableView's didSelectRowAtIndexPath do following

       - (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
          if(indexPath.row != previousSelectedRow && previousSelectedRow != -1) {
              // hide options or whatever you want to do
              previousSelectedRow = -1;
          }
          else {
              // show your options or other things
              previousSelectedRow = indexPath.row;
          }
       }
      

    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. :)