0
votes

I am making a simple drag and drop app and while checking, the drag operation is not getting registered. I dropped an NSView on MainMenu.xib and then subclassed that NSView.

DropView.h

#import <Cocoa/Cocoa.h>

@interface DropView : NSView <NSDraggingDestination>
@property (nonatomic, strong) NSImage *image;
@end

DropView.m

#import "DropView.h"

@implementation DropView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       [self registerForDraggedTypes: [NSImage imagePasteboardTypes]];
    }
return self;
}

- (NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender{
if ([NSImage canInitWithPasteboard:[sender draggingPasteboard]] && [sender draggingSourceOperationMask] & NSDragOperationCopy ) {
    return NSDragOperationCopy;
}
return NSDragOperationNone;
}

- (NSDragOperation) draggingUpdated:(id<NSDraggingInfo>)sender{
    NSLog(@"DRAGGING!");
    return NSDragOperationCopy;
}

-(void) draggingEnded:(id<NSDraggingInfo>)sender{
    NSLog(@"ENDED!");
}

-(void) draggingExited:(id<NSDraggingInfo>)sender{
    NSLog(@"EXITED");
}

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];

    // Drawing code here.
}

@end

When I run this, and try to drop an image, the cursor is not changing to the + signed one. and the methods are not getting logged. Any idea?

1

1 Answers

0
votes

If you're dragging image files onto your window, (?) then I think you want NSFilenamesPboardType :

    [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];