简体   繁体   English

如何从UIPanGestureRecognizer识别触摸的单元格?

[英]How to identify touched Cell from UIPanGestureRecognizer?

I am using UIPanGestureRecognizer to "drag" a Cell. 我正在使用UIPanGestureRecognizer来“拖动”单元格。 The problem I face is to how identify the touched Cell? 我面临的问题是如何识别触摸的单元格? The didSelectRowAtIndexPath won't work for me because the user is actually panning from the cell and not selecting it. didSelectRowAtIndexPath对我不起作用,因为用户实际上是从单元格平移而不选择它。 Does anyone have any suggestion? 有人有什么建议吗? Thanks! 谢谢!

If you add the gesture recognizer to the UITableView , then in your gesture recognizer target do this: 如果将手势识别器添加到UITableView ,则在手势识别器目标中执行以下操作:

CGPoint locationOfPan = [recognizer locationInView:self.tableView];
NSIndexPath indexPath = [self.tableView indexPathForRowAtPoint:locationOfPan];

you can then get the cell from the table view 然后您可以从表格视图中获取单元格

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM