Drag and Drop in uitableview

I am currently developing an application in which the user displays a list in the form of a table. when the user selects a specific row, he can drag it to another row. When this happens, a warning is displayed giving some specific information. Any idea on how to do this.

What I do is that I use gesture recognizers. When a specific row is selected, an image of the selected row is created, which is then dragged into a specific cell of the table view. I can move the image, but my problem is that if I do not become an imageView under the UIView, drag and drop will not happen .....

My drag-and-drop code based on apple concerns the sample code .

Update:

Having tried for some time, I can almost realize this. I still have one doubt. I create a cell image after listening to it. Then a UIPanGestureRecognizer was added to this image, which it turns, makes its movement possible. The only problem is how can I find out on which cell the image was shot?

+7
source share
2 answers

you must implement:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 

which will return YES as well as implememt:

 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { //do whatever u want after row has been moved } 

and then call this function from tableView:

 - (void)setEditing:(BOOL)editing animated:(BOOL)animated 

to enter edit mode.

+9
source

This is an example drag-n-drop cell application in a UITableView using native delegation methods and a dataSource UITableView. https://github.com/coderDove/UITableView-Drag-n-Drop

+7
source

All Articles