2013-05-25 45 views
0

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

沒有調用didDeselectRowAtIndexPath:,有沒有其他方法我忽略?

編輯的解決方案:

細胞永遠不會被取消,因此仍然indexPathForSelectedRow返回正確的值。很公平。

回答

0

您可以使用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]; 
} 
+0

嗨,薩米爾,不完全確定你的意思。我編輯我的問題,也許它不清楚 – ceekay

0

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

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

相關問題