janeh
janeh

Reputation: 3804

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

Upvotes: 4

Views: 1586

Answers (1)

Nate Chandler
Nate Chandler

Reputation: 4553

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.

Upvotes: 5

Related Questions