簡體   English   中英

如何查找調用[tableView setEditing:NO]時選擇的單元格indexPath?

[英]How to find cell indexPath that was selected when calling [tableView setEditing:NO]?

在允許在編輯模式下進行選擇的tableView上,當我調用[tableView setEditing:NO animation:YES]並退出編輯模式時,如何查找選擇的單元格?

沒有對didDeselectRowAtIndexPath:的調用,是否還有其他我忽略的方法?

編輯解決方案:

永遠不會取消選擇該單元格,因此indexPathForSelectedRow仍返回正確的值。 很公平。

您可以為此使用GestureRecognizer。

嘗試這個 :

   UISwipeGestureRecognizer *gestureObj = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(Method:)];
  [gestureObj setDirection:UISwipeGestureRecognizerDirectionRight];
  [self.tableview addGestureRecognizer:gestureObj];


-(void)Method:(UISwipeGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self.tableview];

    NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:p];
    if (indexPath == nil)
    {
        [self setEditing:YES animated:YES];
        NSLog(@"slide on table view but not on a row");
    }

    else
    {
        [self setEditing:YES animated:YES];
        NSLog(@"slide on table view at row %d", indexPath.row);
    }
    UITableViewCell *cell = [self.MYArray objectAtIndex:indexPath.row];
}

答案是該行永遠不會被取消選擇。

在實際退出編輯模式之前,indexPathForSelectedRow仍然有效。

暫無
暫無

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

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