1

I'm trying to detect when a user drops an image on an NSImageView instantiated by code, not as an Outlet.

The idea is that when the image is released an action occurs. How could I do this with code?

let imageHolder = NSImageView(frame: NSRect(x: 0, y: 0, width: 256, height: 256))
imageHolder.image = NSImage.init(named: "picture")
imageHolder.wantsLayer = true
imageHolder.isEditable = true
view.addSubview(imageHolder)
  • Possible duplicate of [Swift OSX NSImageView Drag and Drop](https://stackoverflow.com/questions/46041910/swift-osx-nsimageview-drag-and-drop) – Willeke May 24 '19 at 21:55
  • I need to know how could do this without an action or IBOutlet. So this other questions doesn't answer to my problem. – Chema Juárez May 26 '19 at 15:38
  • Why don't you want to use the action method callback? – Willeke May 26 '19 at 22:32
  • Sorry, I'm very new with Swift. Is there any way to use an action method callback without using an IBOutlet? How? – Chema Juárez May 29 '19 at 15:31
  • You need a pointer to the image view like `imageHolder`, no need for an `IBOutlet`. Set `action` and `target` of `imageHolder` in code. See [create nsbutton manually - call function](https://stackoverflow.com/questions/48102130/create-nsbutton-manually-call-function) – Willeke May 29 '19 at 22:42

0 Answers0