IOS: move a table cell to another section

I have a UITableView with some sections and rows.

I want to move one row from one section to another when I call a function (so it’s not my fingers and I don’t want to use the UITableView edit mode).

How can i do this?

If I recreate the data source and reload the table, this is normal, but does not use animation.

+4
source share
1 answer

UITableView offers you the following methods:

call beginUpdates , update your data source, call moveRowAtIndexPath and finally call endUpdates on a UITableView

 [tableView beginUpdates]; // update your datasource // ... // fill in your indexpath of old and new position [tableView moveRowAtIndexPath: ... toIndexPath: ...]; [tableView endUpdates]; 

EDIT: moveRowAtIndexPath is for iOS 5+ only, so you would rather use this:

 [tableView insertRowsAtIndexPaths: ... withRowAnimation:...]; [tableView deleteRowsAtIndexPaths: ... withRowAnimation:...]; 
+2
source

Source: https://habr.com/ru/post/1388592/


All Articles