> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to