Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag & drop (<NSDraggingDestination>) in Cocoa does not work
    text
    copied!<p>I want to implement some "simple" drag &amp; drop into my Mac application. I dragged in a view and entered "MyView" in my nib file accordingly.However I do not get any response in my console (I try to log messages whenever any of the protocol methods are triggered)</p> <p>I have subclassed NSView like this: </p> <pre><code>@interface MyView : NSView &lt;NSDraggingDestination&gt;{ NSImageView* imageView; } </code></pre> <p>and implement it like this:</p> <pre><code>- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { [self registerForDraggedTypes:[NSImage imagePasteboardTypes]]; NSRect rect = NSMakeRect(150, 0, 400, 300); imageView = [[NSImageView alloc] initWithFrame:rect]; [imageView setImageScaling:NSScaleNone]; [imageView setImage:[NSImage imageNamed:@"test.png"]]; [self addSubview:imageView]; } return self; } - (NSDragOperation)draggingEntered:(id &lt;NSDraggingInfo&gt;)sender{ NSLog(@"entered"); return NSDragOperationCopy; } - (NSDragOperation)draggingUpdated:(id &lt;NSDraggingInfo&gt;)sender{ return NSDragOperationCopy; } - (void)draggingExited:(id &lt;NSDraggingInfo&gt;)sender{ NSLog(@"exited"); } - (BOOL)prepareForDragOperation:(id &lt;NSDraggingInfo&gt;)sender{ NSLog(@"som"); return YES; } - (BOOL)performDragOperation:(id&lt;NSDraggingInfo&gt;)sender { NSPasteboard *pboard = [sender draggingPasteboard]; if ( [[pboard types] containsObject:NSURLPboardType] ) { NSURL *fileURL = [NSURL URLFromPasteboard:pboard]; NSLog(@"%@", fileURL); } return YES; } - (void)concludeDragOperation:(id &lt;NSDraggingInfo&gt;)sender{ NSLog(@"conclude sth"); } - (void)draggingEnded:(id &lt;NSDraggingInfo&gt;)sender{ NSLog(@"ended"); } - (BOOL)wantsPeriodicDraggingUpdates{ NSLog(@"wants updates"); } - (void)updateDraggingItemsForDrag:(id &lt;NSDraggingInfo&gt;)sender NS_AVAILABLE_MAC(10_7){ } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload