简体   繁体   English

如何通过拖动UIImageView来获取UITableView的行索引

[英]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.

相关问题 如何获取存在于UITableView的UITableVIewCell上的UIImageView对象的选定索引路径? - How to get the selected index path for UIImageView object present on a UITableVIewCell of UITableView? UITableView:如何禁用将项目拖动到特定行? - UITableView: how to disable dragging of items to a specific row? 获取将在UITableView中插入的行的索引 - get the index of the row that will be inserted in UITableView 如何在UITableView的单元格中获取UIImageView的touchesMoved? - how to get touchesMoved for UIImageView within a cell of UITableView? 如何使用Swift3在第二个UITableView中获取第一个UITableView的索引path.row - How can I get the index path.row of first UITableView in the Second UITableView using Swift3 获取UITableView中最后一行的索引路径 - Get the index path of last row in UITableView 将UITableView行拖到其他部分会导致崩溃 - Dragging UITableView row to a different section results in crash UIImageView在iOS的UITableView中的单元格行后面消失了 - UIImageView is disappearing behind cell row in UITableView in iOS 在UITableView中选择具有过滤结果的行时,如何获取实际的数组索引值? 迅速 - How to get the actual arrays index value, when selecting a row in UITableView with filtered results? Swift 如何从UITableView获取行索引,UITableView将数组列表附加到类上 - How to get row index from UITableView which the array list made by append to a class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM