Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa - Assign onClick event to NSMenu

I want my status menu to call a function when it is clicked. What's the method that would let me assign that action? Something like this below but for the menu itself.

NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:@"Title" action:@selector(doX) keyEquivalent:@""];

like image 356
janeh Avatar asked Oct 22 '25 23:10

janeh


1 Answers

You can hook into the menu opening event by setting your menu's delegate and implementing the protocol method -[<NSMenuDelegate> menuWillOpen:] in the delegate you designate.

like image 85
Nate Chandler Avatar answered Oct 25 '25 22:10

Nate Chandler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!