0

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"]];
SuperBerry
  • 1,193
  • 1
  • 12
  • 28

3 Answers3

2

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 
}
maquannene
  • 2,257
  • 1
  • 12
  • 10
0
  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

El Tomato
  • 6,479
  • 6
  • 46
  • 75
  • I use XCode V5.1.1 and cannot find that. However I find the solution finally. I write the (void)draggingEnded in the new class: [imgView setImage:[NSImage imageNamed:@"default.jpg"]]; Solved! :) – SuperBerry Dec 10 '15 at 01:04
0

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

override func concludeDragOperation(_ sender: NSDraggingInfo?) {
    return
}
Ewan
  • 31
  • 1