ios - 如何通过滑动手势获取 IndexPath 和 UItableView

标签 ios objective-c iphone uitableview

我有一个 UITableView,其中添加了 UISwipeGesture,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:kCellIndetifier];

UISwipeGestureRecognizer* gestureR;
gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:gestureR];
  return cell;
}

我的选择器在滑动时有响应。

现在我想基于 SwipeGesture 操作单元格。但我无法获取 indexPathUITableView。我怎样才能让这些来操纵细胞。或者他们有其他方式这样做吗?

请帮助我。

最佳答案

你可以做如下的事情..

UISwipeGestureRecognizer* gestureR;
gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:gestureR];


-(void)handleSwipeFrom:(UIGestureRecognizer *)tap{
    CGPoint touch           = [tap locationInView:yourtableview];
    NSIndexPath *indexPath  = [yourtableview indexPathForRowAtPoint:touch];
    CustomCell *cell      = [yourtableview cellForRowAtIndexPath:indexPath];

}

让我知道它是否有效。

祝你编码愉快!!!

关于ios - 如何通过滑动手势获取 IndexPath 和 UItableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33117950/

相关文章:

ios - SQLite 查询 WHERE 和 NSNumber 在处理参数时给出 BAD ACCESS 错误

iphone - ASIHTTPRequest completionBlock + ARC

iphone - 为什么我在启动 iPhone OS 应用程序时得到 "security policy error"?

ios - 手动设置 UIButton 状态

objective-c - iOS 相机 UIView 在 iPad 上覆盖全屏?

ios - privateQueue managedObjectContext 的奇怪问题

ios - 如何使用 UIBarButtonItem 作为菜单按钮将其作为图像移动到左侧?

iPhone 上的 jquery 移动网站

ios - Http Post参数到url不要在objectC Xcode中发送特殊字符 "+"

iphone - 连接两个 View Controller 时出错