簡體   English   中英

如何在iOS中連續檢測兩次連續的點擊

[英]How to detect two consecutive taps on a row in iOS

在我的應用程序中,我希望用戶在行上單擊兩次以顯示警報視圖,以顯示所選行中的詳細信息。 目前,我還執行了另外兩個手勢,即從左向右滑動並長按1秒鍾。 這是代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil)
  {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                   reuseIdentifier:@"Cell"] autorelease];
  }

    //long press gesture
    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
                                          initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 1.00;
    [cell addGestureRecognizer:lpgr];
    //end of long press gesture11111
    //swipe left-right
    UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGestureLeftRight:)];
    [swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
    [cell addGestureRecognizer:swipeLeftRight];
    //end of swipe left-right


  [self configureCell:cell atIndexPath:indexPath];

  return cell;
}

我還沒有發現任何可以應用於我的代碼的內容,因此任何建議都將受到贊賞。

您可以通過三種不同的方式(取決於所需的效果和編碼樣式)來執行此操作。

第一種方法是添加一個雙擊手勢識別器(如果您要查找雙擊而不是在任何時間都單擊兩次)。 我認為您可以自己編寫代碼。

第二個是檢測單元格選擇:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Check if the cell at indexPath is currently the tableview's selected cell then you have double tap
}

第三個與第二個相同,除了創建indexPath變量並在didselectrow方法中進行設置。 然后,如果下一個didselectrow調用是完全相同的indexPath,則雙擊。

我的投票將是保存的變量。 我不確定tableview和cell的“ selected”屬性是否可靠。 但是您還必須實現didDeselectRow函數,因為在表didDeselectRow選擇之外的情況下可以調用該函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM