moveItem(at:to:)
Moves an item from one location to another in the collection view.
Declaration
func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath)Parameters
- indexPath:
The index path of the item that you want to move. This parameter must not be
nil. - newIndexPath:
The index path of the item’s new location. This parameter must not be
nil.
Discussion
After rearranging items in your data source object, use this method to synchronize those changes with the collection view. Calling this method lets the collection view know that it must update its internal data structures and possibly update its visual appearance. You can move the item to a different section or to a new location in the same section. The collection view updates the layout as needed to account for the move, animating cells into position in response.
When inserting or deleting multiple sections and items, you can animate all of your changes at once using the performBatchUpdates(_:completionHandler:) method.