TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

NSClickGestureRecognizer issue

Forums > macOS

Update: I've found a way to make it work, by adding a recognizer in storyboard and control dragging an action. I'm still interested to know though how to make it work programmatically if anyone knows.



I'm porting my app to Mac OS, learning as I go, and have run into difficulty with attaching an NSClickGestureRecognizer. My code is simply:

let gesture = NSClickGestureRecognizer(target: self.imageView, action: #selector(self.testFunc))
    gesture.delegate = self
    gesture.numberOfClicksRequired = 1


When I run it a lot is triggered and scrolled in the console, but it's triggered from clicking anywhere in the entirety of the window, and not confined to the imageVIew. The @objc method is not triggered. Everything else in the window, such as the tableView, stops working. I'm suspecting a view hierarchy issue. I'm trying to attach it using an outlet for my imageView. Perhaps this is the wrong way to go about it, or is there something else I am overlooking?


Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.