0
votes

I have coded drag & drop for the NSImageView, and I set the NSImageView as the PDF/image files drop zone. But I found once the files dropped, the NSImageView shows the dropped file content and image. How can I avoid that? I want NSImageView shows the default image I set when the application launch. I also tried to add this code but doesn't work:

[imgView setImage:[NSImage imageNamed:@"default.jpg"]];
3
Set the background image of your NSImmgeView object through Interface Builder. Or create your drop box with your NSView, which may be a little bit more difficult, though. - El Tomato
I cannot see any place allows to set the background on Interface Builder for NSImageView - SuperBerry
You are subclassing NSViewImage to create a drop box, right? - El Tomato
Yes, I have subclassed the NSImageView - SuperBerry

3 Answers

2
votes

after you process data, you can clear NSDraggingInfo like this:

override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
    // process your data form NSDraggingInfo

    // and clearContents   
    sender.draggingPasteboard().clearContents()

    return true 
}
0
votes
  1. Create a subclass of ImageView. Remove the drawRect:(NSRect)rect method if there is in its implementation file. You won't need it.

enter image description here

  1. Click on the identity inspector tab of the sidebar to the right. Then enter the name of your imageView subclass after selecting an imageView control, which you have already done, probably.

  2. Click on the attributes inspector tab of the sidebar. Select your imageView control and then enter the name of the background image in the top combobox.

enter image description here

0
votes

Subclass NSImageView and implement following method.
Setting new image with draggingInfo is done from concludeDragOperation by default.

override func concludeDragOperation(_ sender: NSDraggingInfo?) {
    return
}