Search code examples
iosobjective-cuitableviewtouch

touchesBegan not working on UITableView


I have UITableView over the full screen. What I would like to know is to find the location where I clicked a cell.

What I want to do is to show the copy option when any cell is clicked.

For that I tried

- (void) touchesEnded:(NSSet *)touches
withEvent:(UIEvent *)event {
    //some code
}

but this method is not getting called.

Any idea how can I find user touch over UITableView


Solution

  • if you just want to show Copy option when any cell is clicked then you have to go for

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    

    method of tableView. there is no need to use Touch event.

    Using this method you can get the copy of selected cell using indexPath.

    Edit

    To get the position of selected cell you can use rectForRowAtIndexPath method

    CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
    

    Edit2

    CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];