Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从tableview获取扫描的tableview单元格_Iphone_Ios_Objective C_Uitableview_Uigesturerecognizer - Fatal编程技术网

Iphone 从tableview获取扫描的tableview单元格

Iphone 从tableview获取扫描的tableview单元格,iphone,ios,objective-c,uitableview,uigesturerecognizer,Iphone,Ios,Objective C,Uitableview,Uigesturerecognizer,我需要你的帮助 我在自定义的TableViewCell中有一个UIPanGesture。 我需要确定在UITableView的UIViewController中平移了哪个单元格 我有两个问题: 如何获得平移TableViewCell(可能通过indexpath) 我应该将代码放在UITableView的方法中的什么位置来获取它 非常感谢 Andrea如果我理解正确,您想知道UIPanGesture在UITableView的哪一部分结束,对吗 我将使用UITableView方法indexPathF

我需要你的帮助

我在自定义的
TableViewCell
中有一个
UIPanGesture
。 我需要确定在
UITableView
UIViewController
中平移了哪个单元格

我有两个问题:

  • 如何获得平移
    TableViewCell
    (可能通过indexpath)

  • 我应该将代码放在
    UITableView
    的方法中的什么位置来获取它

  • 非常感谢


    Andrea

    如果我理解正确,您想知道UIPanGesture在UITableView的哪一部分结束,对吗

    我将使用UITableView方法indexPathForRowAtPoint:来获取您的indexPath


    我没有使用手势识别器的经验,但如果有机会得到一个工作示例,我会更新我的答案。如果你能详细说明UIPanGesture正在做什么,或者为什么你需要UITableViewCell,那会很有帮助。

    如果我读对了你的问题,听起来你想在每个表格视图单元格中添加滑动手势,然后能够获得该单元格的索引。如果这就是你想要的,你可以做以下的事情。这似乎类似于这个问题:但我确实为您提供了实现:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //Do what you need to to get your current cell
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifer:@"prototypeCellId";
    
        //create swipe gesture and add it to cell
        UISwipeGestureRecognizer* swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwiped:)];
        [swipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
        [cell addGestureRecognizer:swipeRecognizer];
    
        return cell;
    }
    
    - (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer 
    {
        if (gestureRecognizer.state == UIGestureRecognizerStateEnded) 
        {
        UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view;
        NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
    
        //do what you want with the indexPath (or cell)
        }
    }
    

    我用这行代码解决了我的问题:SCViewController vista=(SCViewController)tableview.dataSource;vista.swipedIndexPath=\u PannedIndexpath;通过这种方式,我将扫描单元格的索引路径发送到表视图,该路径位于uitableviewcell中。

    您这样做的目的是什么?我不清楚,我已经在其类中找到了平移的tableview单元格,但我不知道如何在tableview的uiviewcontroller中传递它。在这次编辑之前,我直接在CellForRowatinexPath的方法中初始化了一个滑动手势,一切都很好。没错!换句话说,我需要弄清楚这个手势是在哪个单元格里做的!!问题是手势在uitableview的单元格中初始化(由于平移手势实现)。我用这行代码解决了我的问题:
    SCViewController*vista=(SCViewController*)tableview.dataSource;vista.swipedIndexPath=\u PannedIndexpath通过这种方式,我将扫描单元格的索引路径发送到表视图,该路径位于uitableviewcell中。