Can anyone please provide me a sample for table view drag & drop functionality?
            Asked
            
        
        
            Active
            
        
            Viewed 5,425 times
        
    1
            
            
        - 
                    possible duplicate of http://stackoverflow.com/questions/3481858/tutorial-on-how-to-drag-and-drop-item-from-uitableview-to-uitableview – jussi Sep 05 '11 at 11:08
 
2 Answers
4
            When you create a subclass of UITableView controller, uncomment the following methods (or just add them if you are implementing UITableView delegate and dataSource protocols in custom class):
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
    // update your model
}
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
Now you just need an edit button to start editing mode (you can put it in viewDidLoad):
self.navigationItem.rightBarButtonItem = self.editButtonItem;
And inside that tableView:moveRowAtIndexPath:toIndexPath: method you should update your model by rearranging array or whatever is holding your data.
        Filip Radelic
        
- 26,607
 - 8
 - 71
 - 97