Re: UITableView: combining row moves with insert/delete/reload in animation
Re: UITableView: combining row moves with insert/delete/reload in animation
- Subject: Re: UITableView: combining row moves with insert/delete/reload in animation
- From: Luke Hiesterman <email@hidden>
- Date: Tue, 08 Mar 2016 19:58:36 +0000
- Thread-topic: UITableView: combining row moves with insert/delete/reload in animation
If you’re getting asked to create a row at index 3 from that code snippet, then that looks like a UIKit bug. I’d advise filing it at bugreport.apple.com including a sample app showing that behavior.
Luke
> On Mar 8, 2016, at 11:26 AM, Jens Alfke <email@hidden> wrote:
>
> I’m animating a UITableView in response to its backing data changing. I’ve gotten it working with row insertion, deletion and reloads, but now I’m trying to add row movement and it seems like I’ve blown the little view’s mind. Does anyone have experience at combining -moveRowAtIndexPath: with the other operations inside a beginUpdates…endUpdates block?
>
> Here’s an example of what’s not working. Assume the backing store changes from [A, B, C, D, E, F] to [A, E, B, C, G, F]. This can be expressed as “move row 4 to index 1” and “change (the old) row 3 from 'D' to ‘G’”. So I call:
> [table beginUpdates];
> [table moveRowAtIndexPath: 4 toIndexPath: 1];
> [table reloadRowsAtIndexPaths: @[@3]];
> [table endUpdates];
> (For simplicity I’m showing the parameters as integers instead of NSIndexPaths.)
>
> This doesn’t work; what ends up displayed (vertically) is [A, E, B, C, C, F]. Row 4 is C when it should be G. After the -endUpdates call, my dataSource is asked to create a cell at row 3, which it populates with a C. So it looks like the table view is processing the reload before the move, but without taking into account the reordering. So it asks my data source for row 3 when it should ask for row 4.
>
> So then I tried changing using the new row number (4) in -reloadRowsAtIndexPaths:. This causes an assertion failure down within -endUpdates — "attempt to perform a delete and a move from the same index path”.
>
> The docs have no advice; the Table View Programming Guide says nothing about -moveRowAtIndexPath:toIndexPath:. The API doc for that method says "You can combine row-move operations with row-insertion and row-deletion operations within a beginUpdates–endUpdates block to have all changes occur together as a single animation” but doesn’t discuss the nuances of row numbering or ordering of operations.
>
> Anyone got a clue?
>
> —Jens
>
> PS: iOS 9.2 (only simulator so far)
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden