• 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: NSValue, Drag & Drop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSValue, Drag & Drop


  • Subject: Re: NSValue, Drag & Drop
  • From: Scott Anguish <email@hidden>
  • Date: Sun, 9 Nov 2003 20:32:05 -0500

a much easier way of dealing with this is setting a variable (either global, static or even an instance variable) containing the object at the start of the drag.. then when the drag completes, see if that variable has a value..if it does, it's an internal drag, and there is your object.

This is the way the drag and drop outlineview example works /Developer/Examples/AppKit


On Nov 9, 2003, at 2:43 PM, Duncan Oliver wrote:

I have a outlineView that I want to enable internal dragging and dropping in. I've been trying to write NSValue objects to the dragging Pasteboard and retrieve those values in the acceptDrop method. I can write the values to the pasteboard fine, but when I try to make an array using propertyListForType, nothing is written. When making a mutable array (using PropertyListSerialization) the error string says that there are too few bytes.

Here's the code:

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
{
NSMutableArray *collectionObjectArray = [NSMutableArray array];
NSEnumerator *enumerator = [items objectEnumerator];
NSMutableDictionary *object;
BOOL success;

while (object = [enumerator nextObject])
{
[collectionObjectArray addObject:[NSValue valueWithPointer:object]];
}

//Set dragged objects
[pboard declareTypes:[NSArray arrayWithObjects:@"CollectionObjectPboardType", nil] owner:nil];
success = ([pboard setPropertyList:collectionObjectArray
forType:@"CollectionObjectPboardType"]);
return success;
}

- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
NSArray *array;
NSEnumerator *enumerator;
NSValue *objectPointer;

//Make mutable array from dragged object array
array = [[info draggingPasteboard] propertyListForType:@"CollectionObjectPboardType"];
NSLog([[NSNumber numberWithInt:[array count]] stringValue]);
}

The log returns a count of 0:

Here's the initialization code using NSPropertyListSerialization:

{
format = nil;

array = [NSPropertyListSerialization propertyListFromData:[[info draggingPasteboard] dataForType:@"CollectionObjectPboardType"]
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:format
errorDescription:&error];

NSLog(error);
}

This is where log returns the too few bytes error.

Does anyone have an idea what I've done wrong? I'm using Xcode 1.0 on Mac OS X 10.3. Thanks.

Duncan Oliver
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSValue, Drag & Drop (From: Duncan Oliver <email@hidden>)

  • Prev by Date: Re: best practices for globals/identifiers in a Cocoa app
  • Next by Date: Re: NSArrayController population
  • Previous by thread: Re: NSValue, Drag & Drop
  • Next by thread: NSKeyedArchiver, XML, and nibs
  • Index(es):
    • Date
    • Thread