我正在开发一个应用程序,它要求我将一个彩色框(一个 UIImageView)拖到 UITableView 的一行之上。当我释放特定行上的彩色框时,我想将该行的颜色更改为框的颜色。 目前我可以拖放该框,但在获取我释放触摸的行的行索引时遇到问题。 所附图片描述了我想要做的事情。我已将红色框拖到蓝色行上,我想将该行的颜色从蓝色更改为红色。但是我想不出一种方法来获取我放置框的行索引。
最佳答案
你可以通过在 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/