• 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: Drag and drop in collectionview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drag and drop in collectionview


  • Subject: Re: Drag and drop in collectionview
  • From: Gordon Apple <email@hidden>
  • Date: Sun, 29 Jan 2012 11:51:06 -0600
  • Thread-topic: Drag and drop in collectionview

> If you are just trying to rearrange things in your list, you do not need to
> get involved with the pasteboard.  Rearranging arrays (or ordered sets) is a
> little tricky, especially if you want to drag a dispersed collection to a
> specific location which is in or after the extent of the selection.  You have
> to figure out how first removing the objects affects your insertion index,
> then insert them back in at the modified row index.  Note that if you are
> using table bindings, you want to operate on the original array which your
> array controller manages, then let the bindings update the table.
>
> I just did this (in a viewController) last night for an NSOrderedSet using the
> following:
>
> - (void) moveSelectedObjectsToRow:(NSUInteger)row {
>     NSIndexSet *indexes = [(NSArrayController*)self.representedObject
> selectionIndexes];
>     NSRange rangeAbove = NSMakeRange(0, row);   //  Range of all objects above
> row in table.
>     NSUInteger numAbove = [indexes countOfIndexesInRange:rangeAbove];  //  Num
> selected above row in table.
>     NSUInteger newRow = row - numAbove;  //  Where we move selection to.
>     [self.parentBase moveSublistObjectsAtIndexes:indexes toIndex:newRow];   //
> Replace this for Arrays.
> }
>
>
> Using an array instead of an orderedSet, the last line will be different.  At
> that point, you need to move the selected objects from the array into a temp
> array, then reinsert at ³newRow².  None of this involves the pasteboard.
>
> I wish they would include a method to do this, but even the ³move² method in
> NSMutableOrderedSet does not do what is typically wanted, at least without
> doing the above yourself.
>
>> >Follow up : >Reading some more, I've found that I could just use a custom
>> representation for my objects, containing their index in the model >array, to
>> write to the pasteboard, and then use that index to perform to move when the
>> dragging session is accepted. On 28 Jan 2012, at 13:35, Luc Van Bogaert
>> wrote: > > I'm implementing drag and drop for a NSCollectionView. The idea is
>> to rearrange objects in the collection by dragging them to another location.
>> Having read the docs for NSCollectionViewDelegate and NSPasteboard, I still
>> have a few general questions about the concept.

_______________________________________________

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


  • Prev by Date: Re: Subclassing IKImageView
  • Next by Date: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
  • Previous by thread: Re: Drag and drop in collectionview
  • Next by thread: Key Value Observing of NSMutableArray inside an object
  • Index(es):
    • Date
    • Thread