How move/reorder cells from TableView1 to TableView2

前端 未结 1 1453
栀梦
栀梦 2020-12-10 07:29

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

I need to copy/move a cell from the first tableView to the second, similar how is done with

相关标签:
1条回答
  • 2020-12-10 08:07

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

    0 讨论(0)
提交回复
热议问题