Re: Reordering a table insanity
Re: Reordering a table insanity
- Subject: Re: Reordering a table insanity
- From: Quincey Morris <email@hidden>
- Date: Tue, 27 Nov 2012 18:52:22 -0800
On Nov 27, 2012, at 16:24 , Graham Cox <email@hidden> wrote:
> The problem is that as I iterate over the items being moved, this changes the order, so the indexes get messed up, and the items end up in the wrong places. I'm trying to work out how to compensate for the move but I must be having a brainfade sort of day and can't get anything quite right, which is why it's driving me round the bend.
>
> Can anyone point me in the right direction?
>
> Essentially my code is:
>
> index = [items firstIndex];
>
> while( index != NSNotFound )
> {
> [table moveRowAtIndex:index toIndex:targetIndex];
>
> index = [items indexGreaterThanIndex:index];
>
> // do something to the index to make it right having moved the row I'm iterating
> }
>
> where <items> is the NSIndexSet containing the original selection being dragged.
I assume you're using begin/endUpdates around this loop to have a single animation for the whole thing? In that case, it'd be a lot easier to use removeRowsAtIndexes/insertRowsAtIndexes, since the only index that needs to be adjusted is targetIndex (it needs to be decreased by the number of indexes in items that are less than the original targetIndex). That is, you would adjust targetIndex after the removal and before constructing the index set for the insertion.
If you really want to loop doing moveRowAtIndex, then you'd have to adjust targetIndex and every unused index in items, after every step of the move. It's probably not so very hard, but I doubt that anything short of a hit of a mind-altering drug is gonna make it fun to do.
_______________________________________________
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