• 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
Custom objects in drag pasteboard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom objects in drag pasteboard?


  • Subject: Custom objects in drag pasteboard?
  • From: Michael Carter <email@hidden>
  • Date: Wed, 1 Jun 2005 21:56:50 -0700

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
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Custom objects in drag pasteboard?
      • From: Julian <email@hidden>
  • Prev by Date: Re: Bindings & NSTableView: setting cell as 'editable' based on another property
  • Next by Date: Can't *READ* from my Resources Directory???
  • Previous by thread: Binding NSTableView Column Headers vs Cells (was: Bindings & NSTableView: setting cell as 'editable'...)
  • Next by thread: Re: Custom objects in drag pasteboard?
  • Index(es):
    • Date
    • Thread