Hey all.
I'm attempting to add custom objects to the pasteboard passed into tableView:writeRows:toPasteboard:. Watching the clipboard with Clipboard Viewer I don't see anything for the custom datatype in the drag pasteboard after the operation. If I change from my custom type to NSString, it works fine. I based my code on mmalc's Bookmarks example.
This is all happening in my AppController class. I initially register for drags:
// register for drag and drop NSLog( @"registering for drags." ); [jobsView registerForDraggedTypes: [NSArray arrayWithObjects: CopiedRowsType, MovedRowsType, nil]]; [routesView registerForDraggedTypes: [NSArray arrayWithObjects: CopiedRowsType, MovedRowsType, nil]]; [jobsView setAllowsMultipleSelection:YES];
Then when a drag starts I copy my custom objects into an array which is then set as a propertyListItem for the pasteboard:
- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard { // get the contents of the drag and put it on the pboard. NSArray *dataTypes = [NSArray arrayWithObjects: CopiedRowsType, MovedRowsType, nil]; [pboard declareTypes:dataTypes owner:self];
// place the indices of moved rows onto the pboard [pboard setPropertyList:rows forType:MovedRowsType];
// Additionally, create a pboard entry for row copying NSMutableArray *rowCopies = [NSMutableArray arrayWithCapacity:[rows count]]; NSEnumerator *rowEnumerator = [rows objectEnumerator]; NSNumber *idx;
RouteList *r = [[routeController selectedObjects] objectAtIndex:0]; NSLog( @"Working with RouteList %@", [r valueForKeyPath:@"properties.name"] );
while (idx = [rowEnumerator nextObject]) { NSLog( @"Adding job %@ to array", [[r objectInJobsAtIndex: [idx intValue]] valueForKeyPath:@"properties.name"] ); [rowCopies addObject: [r objectInJobsAtIndex:[idx intValue]]]; } [rowCopies addObject:@"Spammy"];
// NSLog( @"Objects in array: %@", [rowCopies count] ); if( [pboard setPropertyList:rowCopies forType:CopiedRowsType] == NO ) NSLog( @"Error setting property list for rowCopies" );
return YES; }
The operations for putting rows into the pboard works fine and persists after the program exits. the drag pasteboard shows 0 objects in COPIED_ROWS_TYPE. When I create the mutable array and copy custom objects into it, I see that they are being added, however, any call to [rowCopies count] always results in a crash.
Any ideas?
Thanks.
#mikec |