views:

210

answers:

1

Hey all,

if i reorder rows on my table view, is it possible to save the result only if the user pressed the "Done" Button? (Reorder is working great, but i only want to commit the final result of the positions if the user pressed the Done Button, and not every time a row is moved.)

Is there something like editingStyle == UITableViewCellEditingCellMove in commitEditingStyle?

Or is this only possible in the moveRowAtIndexPath action?

Thanks for help!

+1  A: 

You will need to create some "editing" version of your internal data structure that you commit when the user finished editing. UITableView does not keep track of where the cells are; it relies on you to do that. It just tells you when the user asks to move things. If you don't really want to move them at that point, then you'll need to keep track of where they really are versus the current order in the TableView.

Remember, UITableViews are intentionally dumb. They don't keep track of data. They just draw things. You keep track of data (as the data source), and tell them what to draw when they ask.

I generally recommend that developers separate their actual data into a separate model class, and have the UITableView maintain a separate NSMutableArray based on that model class. In that case, during editing, you would update the UITableView's array, and when finished editing, it would send that array to the model to update the "real" data.

Rob Napier
Hey, thanks for your response. I actually hold my data in an array. My question is more about where to save if the resorting is done.At the moment i loop through my data array on moveRowAtIndexPath and store the positions to my database.But this loop is called every time i resort it. So i think its better for the performance if the save "action" happens in the commitEditingStyle action like Delete.
phx
Just do your database save in setEditing:animated:.
Rob Napier