0

我需要你的帮助..

我有一个UIPanGesture在我的习惯TableViewCellUITableView我应该需要确定在's中已平移了哪个单元格UIViewController

我有两个问题:

  1. 我怎样才能被平移TableViewCell(也许通过 indexpath)..

  2. 我应该把代码放在UITableView's 方法中的哪里来获取它。

非常感谢!!!

安德烈亚

4

3 回答 3

0

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

于 2013-06-10T10:08:49.370 回答
0

如果我正确阅读了您的问题,听起来您想向每个表格视图单元格添加滑动手势,然后能够获取该单元格的索引。如果这是您正在寻找的内容,您可以随时执行以下操作。这看起来类似于这个问题:How to detect a swipe-to-delete gesture in a custom 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)
    }
}
于 2013-06-09T18:50:01.327 回答
0

如果我理解正确,您想弄清楚 UIPanGesture 在 UITableView 的哪一部分结束,对吗?

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

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

于 2013-06-09T18:38:12.083 回答