4

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

janeh
  • 3,734
  • 7
  • 26
  • 43
  • Can you explain little bit more? what do you need? on click event of the application menu? or something else? – Remizorrr Oct 22 '12 at 18:01
  • My NSMenu has a Refresh menu item. When users click on the menu to expand it, the date it was last refreshed should change. I have a method `+(NSString *)formatRefreshDate` that should get called when menu is clicked... – janeh Oct 22 '12 at 18:34

1 Answers1

5

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.

Nate Chandler
  • 4,533
  • 1
  • 23
  • 32