Re: draggingEntered Not Working As Expected
Re: draggingEntered Not Working As Expected
- Subject: Re: draggingEntered Not Working As Expected
- From: Raleigh Ledet <email@hidden>
- Date: Wed, 3 Aug 2011 14:13:54 -0700
On Aug 3, 2011, at 12:29 PM, Chris Tracewell wrote:
> 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?
if your IKImageBrowserView DnD delegate does not implement -draggingUpdated: (because you commented it out) then IKImageBrowserView makes it's own best guess for drag operation. You must implement -draggingUpdated: and return the appropriate value.
>
> 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.
There are actually 3 methods concerned with the drop… -prepareForDragOperation:, -performDragOperation:, and -concludeDragOperation:. In prepare you can make one last determination and decide if you really can accept the drop of not. If you return NO, then the drag is cancelled and perform and conduced are not called. In -performDragOperation:, you should actually update your data modal and return if this was successful or not. If you return NO, conclude is not called. In -concludeDragOperation:, you do any clean up that you need to do (like call setNeedsDisplay or reload). Often you only care about -performDragOperation: and should only implement that one.
In Lion, these 3 methods additional meaning and responsibilities when you are dealing with multi-image, animated drag and drop. In -prepareForDragOperation: you inform the draggingInfo if you want to animate the drop (by modifying properties on sender, the return value still has the same meaning discussed above). If so, then in -performDragOperation: you update your data modal and setup drag item destinations and any animations that you view needs to perform to create drop holes. On return, the drop animation is performed and then -concludeDragOperation: is called. In -concludeDragOperation:, you should invalidate where you are drawing holes and do any needed cleanup, such that the next call to DrawRect will draw the final version of the dropped items in place.
-raleigh
>
>
> --Chris_______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden