[英]How to get the row index of a UITableView by dragging a UIImageView on it
I am developing an app that requires me to drag a colored box that is a UIImageView on top of a row of a UITableView. 我正在开发一个应用程序,要求我将一个彩色框(即UIImageView)拖到UITableView的一行顶部。 When I release the colored box on a specific row, I want to change the color of that row to the color of the box. 当释放特定行上的彩色框时,我想将该行的颜色更改为框的颜色。 Currently I am able to drag and drop the box but I'm facing problem in getting the row index of the row on which I release touch. 目前,我可以拖放框,但是在获取释放触摸的行的行索引时遇到了问题。 The image attached depicts what I want to do. 所附的图像描绘了我想要做什么。 I have dragged the red box on the blue row, and I want to change the color of the row from blue to red. 我已经将蓝色框中的红色框拖了,我想将行的颜色从蓝色更改为红色。 But I cant figure out a way to get the row index on which I drop the box. 但是我想不通一种获取行索引的方法。
You can get tableView cell by getting indexPath at rootPoint, like this. 您可以通过在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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.