如何查找调用[tableView setEditing:NO]时选择的单元格索引路径?

时间:2013-05-25 13:16:50

标签: ios uitableview nsindexpath setediting

在允许在编辑模式下选择的tableView上,当我调用[tableView setEditing:NO animated:YES]并退出编辑模式时,如何找到所选单元格?

没有调用didDeselectRowAtIndexPath:,有没有其他方法我忽略了?

编辑解决方案:

单元格永远不会被取消选择,因此indexPathForSelectedRow仍然返回正确的值。很公平。

2 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分:0)

答案是该行永远不会被取消选择。

indexPathForSelectedRow在实际退出编辑模式之前仍然有效。

相关问题