如何将单元格从 TableView1 移动/重新排序到 TableView2 [英] How move/reorder cells from TableView1 to TableView2

查看:13
本文介绍了如何将单元格从 TableView1 移动/重新排序到 TableView2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 UITableView,在 iPad 屏幕上有不同的数据源.

I have several UITableViews, with different datasources in a iPad screen.

我需要将一个单元格从第一个 tableView 复制/移动到第二个,类似于使用其他语言的 ListBox 完成的操作.

I need to copy/move a cell from the first tableView to the second, similar how is done with ListBox in other languages.

现在,我可以重新排列单元格,但移动仅限于 tableView.我想拖动 tableView1 & 中的单元格放入 tableView2.

Now, I can reorder the cells, but the movement is restricted to the tableView. I want to drag the cell in tableView1 & drop in tableView2.

P.D.我愿意使用任何其他控件来存档它.我看看 AQGridView &DTGridView,但是布局基于具有不同#items 的列.如果我可以使用此控件或其他控件模拟列,那么我可以接受解决方法.

P.D. I'm open to use any other control to archive this. I take a look at AQGridView & DTGridView, however the layout is based in columns with different #items. If I can emulate columns with this controls or other then I can accept the workaround.

更新:

我希望这个链接可以帮助:

I hope this links could help:

观察 UITableView 中的捏合多点触控手势

这是最接近的答案:

在 ipad 的两个表格之间拖放

我知道如何从视图中获取图像,我可以使用 手势识别器,所以我有所有的设置,但没有图形开发方面的专业知识,所以不知道怎么搞定的……

I know how get a image from a view, I can detect the drag with a Gesture Recognizers, so I have all the setup in place but have not expertise in graphic development, so don't know how put this in motion...

推荐答案

这绝对是一个非常有趣的问题,我希望我有时间整理一些测试代码,看看我将要概述的想法是否会实际工作.我希望这至少可以为您指明正确的方向.

This is definitely a very interesting question, and I wish I had the time to put together some test code to see if the idea I'm about to outline would actually work. My hope is that this will at least point you in the right direction.

UITableViewCell 是 UIView 的子类,所以我会创建一个 UITableViewCell 的子类,称为 DraggableTableViewCell 这样我们就可以处理触摸事件,然后执行以下步骤:

UITableViewCell is a subclass of UIView, so I would create a subclass of UITableViewCell called something like DraggableTableViewCell so we can handle the touch events and then perform the following steps:

  1. 创建 DraggableTableViewCell 的实例并将其配置为与选定单元格一样.
  2. 将新单元格作为一个视图的子视图添加到与原始单元格相同位置的两个表中,该视图是一个共同的父视图.
  3. 使用 deleteRowsAtIndexPaths:withRowAnimation:
  4. 更新源表视图的数据源并从表视图中删除原始单元格
  5. 通过响应 touchesMoved:withEvent:
  6. 在显示屏上移动单元格
  7. 当收到 touchesEnded:withEvent: 时,验证该单元格是否与另一个表格视图有些接近,并确定插入新单元格的索引路径
  8. 更新目标表视图的数据源并调用 insertRowsAtIndexPaths:withRowAnimation:
  9. 使用漂亮的动画将您的可拖动单元格从其父视图中移除.
  1. Create an instance of DraggableTableViewCell and configure it to appear like the selected cell.
  2. Add the new cell as a subview of a view that is a common superview to both tables at the same location as the original cell.
  3. Update the data source for the source table view and remove the original cell from the table view using deleteRowsAtIndexPaths:withRowAnimation:
  4. Move the cell on the display by responding to touchesMoved:withEvent:
  5. When touchesEnded:withEvent: is received, verify the cell is somewhat close to the other table view and determine the index path where to insert the new cell
  6. Update the data source for the destination table view and call insertRowsAtIndexPaths:withRowAnimation:
  7. Remove your draggable cell from its superview with a nice animation.

整个过程需要由控制屏幕上各种表格视图的视图控制器进行编排.

This entire process will need to be orchestrated by the view controller that controls the various table views on the screen.

这篇关于如何将单元格从 TableView1 移动/重新排序到 TableView2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆