NSValue, Drag & Drop
NSValue, Drag & Drop
- Subject: NSValue, Drag & Drop
- From: Duncan Oliver <email@hidden>
- Date: Sun, 9 Nov 2003 13:43:58 -0600
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 propertyListFrom
Data:[[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.