On Nov 28, 2012, at 02:17 , Graham Cox <[email protected]> wrote:

> That's my mental picture of the first part, but the outcome is incorrect, so 
> either the algorithm or the implementation is wrong.

I got to wondering further about this, so I downloaded the TableViewPlayground 
sample project. Lo and behold, its "complex table view" window exposes in the 
UI all of the functionality we've been discussing -- begin/endUpdates, 
move/insert/delete -- so it really is a playground.

Turns out we just needed to fathom the mind of Dr. Corbin Seuss. Turns out this:

        [tableView moveRowAtIndex: fromIndex toIndex: toIndex]

does what it says -- it moves the row so that it *is* at toIndex. So, if 
fromIndex < toIndex, the row ends up *after* the row previously at toIndex, but 
if fromIndex >  toIndex, it ends up *before*. IOW, it's working in terms of row 
numbers, not rows.

I believe (though I don't think Graham said explicitly) that Graham's 
particular case wants to move selected rows so they precede the row initially 
at targetIndex, so it wants to work in terms of rows, not row numbers (so to 
speak).

If that's so, I think the loop algorithm needs to look like this:

C1. Loop over the "less than" set starting from its highest index and working 
down. At each iteration, move the row at the current index to 'targetIndex - 
1'. (But don't decrement targetIndex here.)

C2. Loop over the "greater than" set starting from its lowest index and working 
up. At each iteration, move the row at the current index to the targetIndex 
row, and increment targetIndex.

Using TableViewPlayground, I used multiple moves bracketed by begin/endUpdate, 
and it animated very prettily at the endUpdate.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to