0

I'm making a slideshow application in which I want to be able to click the view displaying the slideshow in order to pause or play it. I was hoping that just like with a button, I can send an action to my ViewController and thereby call a function that could for example be called slideshowViewClicked.

I found someone trying to do something similar with Notifications, but sending an action seems to be the correct way to me.

So would someone be able to explain to me how to send actions from a view to its ViewController just like its done with buttons?

Thanks a lot in advance!

Jan Kaiser
  • 830
  • 1
  • 8
  • 22
  • I think this resolve your problem. http://stackoverflow.com/questions/27880607/how-to-assign-an-action-for-uiimageview-object-in-swift – Claudio Castro Feb 01 '17 at 17:45

2 Answers2

0

In your UIView subclass, implement the appropriate mouse event (such as mouseDown) and call slideshowViewClicked.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

You can call -[NSApplication sendAction:to:from:]. If you use nil for the target, the application object will search the responder chain. Otherwise, the action method will be sent directly to the target.

You might consider making your class a subclass of NSControl, although that does involve some baggage. In that case, you'd call the inherited -sendAction:to: method.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154