UITableView animate row reordering upon sort

uitableview reorder rows programmatically swift
uitableview move rows without editing mode
uitableview reorder long press
uitableviewcell custom reorder control
uitableview sort
drag and drop uitableviewcell swift
uitableviewcontroller reorder

I have a table that users can sort in two different ways. When users change between these two sorting modes, I want the re-sort to be animated. And while UITableView's methods provide animation help for inserting, deleting, and reloading rows, I don't see anything that lets me animate row movement.

Am I missing something?

Assuming I'm not, does anyone have any sample code on how to do this?


I know this is an older question, but I ran into the same issue and think I found a solution, so I thought I'd share in case anyone else finds their way here with the same question. I'm also not sure how great of a solution it is, but it seems to work for me.

My TableView gets its data from an array called _objects. In my method for sorting, I begin by creating another array which is an exact copy of the data array:

    NSArray *objectsBeforeSort = [NSArray arrayWithArray:_objects];

I then sort my data array, _objects, using sort descriptors that I had already created. After calling the appropriate sort method on my array, I use this to animate the table update:

[self.tableView beginUpdates];

for (int i = 0; i < _objects.count; i++)
    // newRow will get the new row of an object.  i is the old row.
    int newRow = [_objects indexOfObject:objectsBeforeSort[i]];
    [self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0] toIndexPath:[NSIndexPath indexPathForRow:newRow inSection:0]];

[self.tableView endUpdates];

I haven't tested this code extensively yet, but it appears to give the desired result.

Managing the Reordering of Rows, Managing the Reordering of Rows. A table view has an editing mode as well as its normal (selection) mode. When a table view goes into  The user drags a row by its reordering control up or down the table view. As the dragged row hovers over a part of the table view, the underlying row slides downward to show where the destination would be. Every time the dragged row is over a destination, the table view sends tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: to its delegate (if it implements the method).

Have you tried using moveRowAtIndexPath:toIndexPath: inside a beginUpdates-endUpdates block? It seems to be what the developer docs are currently recommending. If that doesn't work on its own you could also try wrapping it in a [UIView animateWithDuration:animations:] block.

Link to the ADC documentation for UITableView: https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableView

Swift - UITableView reorder rows tutorial, Tutorial on doing reordering rows in a UITableView in Swift. UITableView Previous Tutorial Duration: 10:37 Posted: Jan 24, 2015 Expand rows upon selection in UITableView Forgive my ignorance, I'm a total noob on IOS, and I need some help from some knowledgeable dev. My UITableView needs to have some of it's rows expand on click in order to show some details.

Reorder Table View Rows - Part 44, By the end of this video, sorting cells in table views will be easy! SwiftUI Animations: https Duration: 20:57 Posted: Apr 22, 2019 Table views on iOS display a single column of vertically scrolling content, divided into rows. Each row in the table contains one piece of your app’s content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings.

Contacts: Animations Reload Rows in UITableView (Ep 2), In addition, I show you some tricks on how to toggle animations using a boolean value in your Duration: 16:08 Posted: Nov 17, 2017 Animate UICollectionView cell reordering After sorting products in the model I want to animate UICollectionView cell reordering. I enumerate all products in ordered array, find which row index given product had under old order and tell UICollectionView to moveItemAtIndexPath:toIndexPath from old index path to new index path.

Animating Table View Cells Display, First off, grab the starter project to save some time on boilerplate code and initial setup. If you run it, you see regular UITableView with static cells. Animating Table View Cell Display in Swift: Practical Recipes - Starter Project to create Xcode Source Editor Extension that adds sorting functionality to Xcode. Tutorial on doing reordering rows in a UITableView in Swift. FB Messenger - How to Sort and Filter with Core Data (Ep insert and delete rows with animation - Duration: 25:51. Lets Build

Reorder Rows from Table View iOS Tutorial, Reorder Rows from Table View iOS Tutorial override func tableView(_ tableView: UITableView, cellForRowAt You can download the source code of the iOS12ReorderRowsTutorial at the ioscreator repository on Github. Inserting and Deleting Rows and Sections. A table view has an editing mode as well as its normal (selection) mode. When a table view goes into editing mode, it displays the editing and reordering controls associated with its rows. The editing controls, which are in the left side of the row, allow the user to insert and delete rows in the table

  • tjf has a great answer below. Why not give him some "accepted answer" love?
  • That method is fairly inefficient. Not only do you have to go through the sorting complexity, but then you loop through every object and call indexOfObject: on each one which also does a loop up to O(n)