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

Re: Reordering a table insanity


  • Subject: Re: Reordering a table insanity
  • From: Seth Willits <email@hidden>
  • Date: Tue, 27 Nov 2012 21:55:21 -0800

On Nov 27, 2012, at 8:11 PM, Graham Cox wrote:

> The removal/insertion approach does not produce a similar animation, or even any, despite having a set of NSAnimationOptions. That seems to be the case whether I bracket with begin/endUpdates or not. That strikes me as wrong - I should see an animation here, no? So I must be doing something wrong.

There isn't anything to really do wrong, though. Remove and Insert should each do some fading and shifting, but perhaps the combo happening within a single update makes it do nothing. I thought I had done this before but I can't recall where so I can't look it up and I'm too lazy to make a test case.

Either way, if you want the animated flying rows you'll have to deal with the unfortunate interface of moving one at time. If you're willing to do it "the easy way", then just use liberal use of indexOfObject and looping to do what you want. It'll be "slow" but it might still be fast enough to be plenty fine.

In other words: (I'm thining out loud here)



if the entire list is selected, just bail now to avoid special cases

Get a list of objects at the selected indexes

dropIndex = initial drop index
while (dropIndex is in selectedIndexes and dropIndex < count)
	dropIndex++;

beforeObject = object at dropIndex

(^ if the drop is at the very end of the list dropIndex == count and beforeObject will be nil)


for each selected object
	if beforeObject is nil
		moveRowAtIndex:from toIndex:count
		removeObjectAtIndex:from  in your mutable array
		addObject:
	else
		from = indexOfObject:selectedObject
		to = indexOfObject:beforeObject

		moveRowAtIndex:from toIndex:to

		removeObjectAtIndex:from  in your mutable array
		to -= (to > from);
		insertObjectAtIndex:to
	end
end


I thiiiiiiiiiink that works, and covers the edge cases. I admit I didn't put a ton of thought into this. If you have thoooousands of objects though, the indexOfObjects can get expensive.

Also, be glad it's not an outline view... that can get super confusing in a hurry (what if the selection contains a mixture of ancestors and descendants etc).


Hope that helps,


--
Seth Willits


_______________________________________________

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

References: 
 >Reordering a table insanity (From: Graham Cox <email@hidden>)
 >Re: Reordering a table insanity (From: Quincey Morris <email@hidden>)
 >Re: Reordering a table insanity (From: Graham Cox <email@hidden>)
 >Re: Reordering a table insanity (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Reordering a table insanity
  • Next by Date: Re: Reordering a table insanity
  • Previous by thread: Re: Reordering a table insanity
  • Next by thread: Re: Reordering a table insanity
  • Index(es):
    • Date
    • Thread