• 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
Reordering a table insanity
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Reordering a table insanity
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: split views, best practices for 10.8?
  • Next by Date: Re: split views, best practices for 10.8?
  • Previous by thread: Re: split views, best practices for 10.8?
  • Next by thread: Re: Reordering a table insanity
  • Index(es):
    • Date
    • Thread