Reputation: 690
I have a UITableView
with some sections and rows.
I want to move one row from one section to another section, when I call a function (so not my fingers and I do not want use edit mode of UITableView
).
How can I do this?
If I recreate a datasource and reload table, it's ok, but it not use animation.
Upvotes: 4
Views: 3011
Reputation: 4903
UITableView
offers you methods for this:
call beginUpdates
, update your datasource, call moveRowAtIndexPath and finally call endUpdates
on UITableView
[tableView beginUpdates];
// update your datasource
// ...
// fill in your indexpath of old and new position
[tableView moveRowAtIndexPath: ... toIndexPath: ...];
[tableView endUpdates];
EDIT: moveRowAtIndexPath is only for iOS 5+ so you would rather use this:
[tableView insertRowsAtIndexPaths: ... withRowAnimation:...];
[tableView deleteRowsAtIndexPaths: ... withRowAnimation:...];
Upvotes: 2