• 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 between two table views.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drag and drop between two table views.


  • Subject: Re: Drag and drop between two table views.
  • From: Graham Cox <email@hidden>
  • Date: Thu, 28 Oct 2010 10:48:07 +1100

On 28/10/2010, at 8:45 AM, Paul Johnson wrote:

> I think I've made some progress. I've rewritten tableView:writeRowsWithIndexes:toPasteboard: for the source table view:
>
> 	NSArray *rows = [self arrangedObjects];
> 	NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
>   NSInteger index = [rowIndexes firstIndex];
>
> 	while (index != NSNotFound) {
>     [selectedItems addObject:[rows objectAtIndex:index]];
> 		index = [rowIndexes indexGreaterThanIndex:index];
> 	}

Hi Paul,

You can replace all of the above with:

NSArray* selectedItems = [[self arrangedObjects] objectsAtIndexes:rowIndexes];


>
> 	[pboard declareTypes:[NSArray arrayWithObject:BFDragPasteboardType] owner:nil];

owner should be 'self', not nil.

>   [pboard setPropertyList:selectedItems forType:BFDragPasteboardType];


This should be OK as long as you are certain that the data items conform to the limitations on property lists. Otherwise you might want to archive the array to a NSData object and write it to the pasteboard using -setData:forType:

> Where I'm still having problems is in the array controller for the second table. What I have so far doesn't work:
>
> - (BOOL)tableView:(NSTableView *)aTableView
>        acceptDrop:(id <NSDraggingInfo>)info
>               row:(NSInteger)row
>     dropOperation:(NSTableViewDropOperation)operation {
>   id current;
>   NSPasteboard *pb = [info draggingPasteboard];
>   NSEnumerator *enumerator;
>   enumerator = [[pb propertyListForType:@"selectedItems"] objectEnumerator];

This should be:

NSArray* draggedItems = [pb propertyListForType:BFDragPasteboardType];

That's all - the object returned is an array containing a copy of the original items (assuming that they are compatible with property lists, as above). If not, you should use -dataForType: and dearchive the NSData to recover the array.

Is the method above actually being called? Don't forget you need to register the tableview to receive drags of type 'BFDragPasteboardType' when you set up your interface otherwise it won't even begin to handle any drags.

--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: Drag and drop between two table views.
      • From: Graham Cox <email@hidden>
References: 
 >Drag and drop between two table views. (From: Paul Johnson <email@hidden>)
 >Re: Drag and drop between two table views. (From: Graham Cox <email@hidden>)
 >Re: Drag and drop between two table views. (From: Paul Johnson <email@hidden>)

  • Prev by Date: Handle drop to WebView: WebDragDestinationActionDHTML
  • Next by Date: Re: NSFileManager and Resource Forks
  • Previous by thread: Re: Drag and drop between two table views.
  • Next by thread: Re: Drag and drop between two table views.
  • Index(es):
    • Date
    • Thread