objective-cxcodemacosnsimageview

avoid the NSImageView change the image after drag & drop


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"]];

Solution

    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