How can I detect a double tap on a certain cell in UITableView
?
i.e. I want to perform one action if the user made a single touch and a
This solution is only works for UICollectionView or UITableView's cell.
First declare these variables
int number_of_clicks;
BOOL thread_started;
Then put this code in your didSelectItemAtIndexPath
++number_of_clicks;
if (!thread_started) {
thread_started = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
0.25 * NSEC_PER_SEC),
dispatch_get_main_queue(),^{
if (number_of_clicks == 1) {
ATLog(@"ONE");
}else if(number_of_clicks == 2){
ATLog(@"DOUBLE");
}
number_of_clicks = 0;
thread_started = NO;
});
}
0.25 is the delay of between 2 clicks. I think 0.25 is perfect for detect this type of click. Now you can detect only one click and two clicks seperately. Good Luck