Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drag and drop in uitableview

I am currently developing an application in which a user is displayed a list in the form of a tableview. when the user selects a particular row, he/she can drag it to another row. When that happens an alert is displayed giving some specific information.Any idea as to how it can be done.?

What I am doing is that I am using gesture recognizers.When a particular row is selected, an image of the selected row is made which then is dragged to the specific table view cell.I am able to move the image but my problem is that if I dont put the imageView under a UIView, the dragging stuff does not happen.....

My dragging code is based on apple's touches sample code .

Update:

After trying for some time, I am able to almost implement this.I still have one doubt though.. I am creating an image of a cell once it is tapped.Then UIPanGestureRecognizer has been added to that imageView which it turn makes its movement possible .The only problem is how can I know on which cell the image has been dropped?

like image 911
sandeep sinha Avatar asked Feb 24 '11 14:02

sandeep sinha


2 Answers

you should implement:

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

which will return YES, and also 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 to edit mode.

like image 107
Ratinho Avatar answered Nov 02 '22 12:11

Ratinho


This is a sample of an application with cells drag-n-drop in UITableView using native methods of delegate and dataSource of UITableView. https://github.com/coderDove/UITableView-Drag-n-Drop

like image 30
Anton Holub Avatar answered Nov 02 '22 12:11

Anton Holub