How can I detect a double tap on a certain cell in UITableView?

后端 未结 14 1025
悲哀的现实
悲哀的现实 2020-12-01 00:18

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

14条回答
  •  春和景丽
    2020-12-01 00:37

    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

提交回复
热议问题