Reordering a table insanity
Reordering a table insanity
- Subject: Reordering a table insanity
- From: Graham Cox <email@hidden>
- Date: Wed, 28 Nov 2012 11:24:51 +1100
Hi all,
I'm driving myself insane with this.
I have a table view that can be reordered by dragging. It supports a multiple selection.
When I drag multiple items, which can be a discontiguous selection, and drop them at a given row, I want to animate the reordering, so I'm using -[NSTableView moveRowAtIndex:toIndex:];
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.
As an additional exercise, this table is associated with a mutable array in my data model which must also be reordered to match. Once I can correctly order the table rows this should be much the same thing,
though since NSMutableArray has -itemsAtIndexes:, -removeItemsAtIndexes, etc using those might be a better idea.
What's missing is a -[NSMutableArray moveItemsAtIndexes:(NSIndexSet*) indexes toIndex:(NSUInteger) index]; so how do I implement such a method correctly?
--Graham
_______________________________________________
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