Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTableView drag and drop

NSTableView drag and drop
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Nov 2, 2003, 12:11 PM
 
I'm having a horrible time trying to implement drag and drop between two tables in the same app. I can get the source table to generate the drag and drag the item around, but I can't get the destination table to 'recognize' the drag. I'm trying to drag a dictionary from the source.

Here's how I implement the source drag code:

Code:
- (BOOL) tableView: (NSTableView *) view writeRows: (NSArray *) rows toPasteboard: (NSPasteboard *) pboard { NSLog(@"dragging"); id object = [[self arrangedObjects] objectAtIndex: [[rows lastObject] intValue]]; NSData *data = [NSArchiver archivedDataWithRootObject: object]; [pboard declareTypes: [NSArray arrayWithObject:@"PBtype"] owner: nil]; [pboard setData: data forType:@"PBType"]; return YES; }
Here is the message I send to the destination table to register it to receive the drag:

Code:
[destinationTableView registerForDraggedTypes: [NSArray arrayWithObjects:@"PBType", nil]];
I also implement the following methods in the datasource of the destination table:

Code:
- (NSDragOperation) tableView: (NSTableView *) view validateDrop: (id <NSDraggingInfo>) info proposedRow: (int) row proposedDropOperation: (NSTableViewDropOperation) operation AND - (BOOL) tableView: (NSTableView *) view acceptDrop: (id <NSDraggingInfo>) info row: (int) row dropOperation: (NSTableViewDropOperation) operation
Any ideas what I am doing wrong?

thanks,
kman
     
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Cape Canaveral, FL
Status: Offline
Reply With Quote
Nov 3, 2003, 03:02 PM
 
The first thing I see is that you have PBtype vs. PBType

Code:
[pboard declareTypes: [NSArray arrayWithObject:@"PBtype"] owner: nil]; [pboard setData: data forType:@"PBType"];
Code:
[destinationTableView registerForDraggedTypes: [NSArray arrayWithObjects:@"PBType", nil]];
fix that and see if that helps.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:21 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2