【问题标题】:How to find cell indexPath that was selected when calling [tableView setEditing:NO]?如何找到调用 [tableView setEditing:NO] 时选择的单元格 indexPath?
【发布时间】:2013-05-25 13:16:50
【问题描述】:

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

没有调用 didDeselectRowAtIndexPath:,还有其他我忽略的方法吗?

编辑解决方案:

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

【问题讨论】:

    标签: ios uitableview nsindexpath setediting


    【解决方案1】:

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

    【讨论】:

    • 嗨,Samir,不太清楚你的意思。我编辑我的问题可能不清楚
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-07-02
      • 2015-05-24
      • 1970-01-01
      • 2015-04-20
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多