• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
UITableView: combining row moves with insert/delete/reload in animation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UITableView: combining row moves with insert/delete/reload in animation


  • Subject: UITableView: combining row moves with insert/delete/reload in animation
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 08 Mar 2016 11:26:32 -0800

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


  • Follow-Ups:
    • Re: UITableView: combining row moves with insert/delete/reload in animation
      • From: Luke Hiesterman <email@hidden>
  • Prev by Date: Re: State Restoration thinks all my windows closes prior to quit
  • Next by Date: Re: UITableView: combining row moves with insert/delete/reload in animation
  • Previous by thread: Re: UICollectionView Moving
  • Next by thread: Re: UITableView: combining row moves with insert/delete/reload in animation
  • Index(es):
    • Date
    • Thread