XCode 4, 10.6 GC -- I have an IKImageBrowserView which I have implemented drag
and drop for. I have set my view controller as the image browser's drag
delegate, registered for pasteboard drag types in awakeFromNib and implemented
DnD protocol methods like so...
-(void)awakeFromNib
{
[myProductImageBrowser registerForDraggedTypes: [[NSArray
arrayWithObjects:@"productIndexObjectType",NSFilenamesPboardType, nil]
arrayByAddingObjectsFromArray:[NSImage imagePasteboardTypes]]];
}
-(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSLog(@"DND Entered");
return NSDragOperationNone;
}
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender // validate
position
{
NSLog(@"DND Uppdated");
if ([myProductImageBrowser dropOperation] == IKImageBrowserDropOn)
{
return NSDragOperationEvery;
}
return NSDragOperationNone;
}
-(BOOL)performDragOperation:(id <NSDraggingInfo>)sender // Drop Occured
{
NSLog(@"DND Perform");
NSArray *theFileArray = [[sender draggingPasteboard]
propertyListForType:NSFilenamesPboardType];
if ([theFileArray count] == 1)
{
NSImage *theImage = [[NSImage alloc]
initWithContentsOfFile:[theFileArray objectAtIndex:0]];
if (theImage)
{
TKProductMaster *theProductMaster =
[[myProductMasterArrayController arrangedObjects]
objectAtIndex:[myProductImageBrowser indexAtLocationOfDroppedItem]];
[theProductMaster setMyImage:theImage];
[theProductMaster setImageVersion:[theProductMaster
imageVersion] + 1]; // up the version number so the image browser knows to
trash onld image cache
[myProductImageBrowser reloadData];
return YES;
}
}
return NO;
}
QUESTION #1
I will test for the other pboard types later, but right now what is confusing
me is that draggingEntered, which returns NSDragOperationNone, is not stopping
anything. The logs are showing so it is getting called. I did read in the
NSDraggingDestination Protocol Reference that draggingUpdated & draggingExited
will still get called even if draggingEntered returns NSDragOperationNone.
Okay, but when I comment out draggingUpdated the image browser still accepts
drags. Why? Shouldn't it cut off dragging altogether if draggingUpdated is
never called to return NSDragOperationEvery?
QUESTION #2
I do not understand the difference between prepareForDragOperation: and
performDragOperation: as they both seem to be called at the same time and have
access to the same sender / info. As it is, I am only implementing
performDragOperation to validate the final drop and perform the final work.
--Chris_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]