简体   繁体   中英

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. 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.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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