ios - 如何通过在其上拖动 UIImageView 来获取 UITableView 的行索引

标签 ios iphone uitableview drag-and-drop uiimageview

我正在开发一个应用程序,它要求我将一个彩色框(一个 UIImageView)拖到 UITableView 的一行之上。当我释放特定行上的彩色框时,我想将该行的颜色更改为框的颜色。 目前我可以拖放该框,但在获取我释放触摸的行的行索引时遇到问题。 所附图片描述了我想要做的事情。我已将红色框拖到蓝色行上,我想将该行的颜色从蓝色更改为红色。但是我想不出一种方法来获取我放置框的行索引。 The Image depicts what I want to achieve.

最佳答案

你可以通过在 rootPoint 处获取 indexPath 来获取 tableView 单元格,就像这样。

CGPoint touchPoint = [[touches anyObject] locationInView:self.tableView];

CGPoint cellPoint= [sender.superview convertPoint:touchPoint toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:cellPoint];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

关于ios - 如何通过在其上拖动 UIImageView 来获取 UITableView 的行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21162418/

相关文章:

ios - 自动从 paypal 交易中扣除款项以将其发送给应用程序所有者

ios - 如何将文本分配给 tableView 中的单元格?

uitableview - tvOS UITableView 单元格聚焦

ios - 如何使用 faSTLane 将详细的测试结果发布到 slack?

ios - 我是否需要 block 中的 strongSelf 来保持 self 存活并且 strongSelf 真的有效吗?

ios - 如何在单击自定义单元格的按钮中获取单元格对象?

iphone - 我需要苹果订阅之外的替代品建议吗?

iphone - UIWebView 中的异步 HTTP 请求真的会产生新线程吗?

iPhone 显示与模拟器不同

ios - 无法以编程方式选择 UITableViewCell