How to know menu items( about or quit) clicked
I am using notification to get control when menu items clicked...
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuChangedItem:) name:NSMenuWillSendActionNotification object:nil];
}
-(void) menuChangedItem :(NSNotification *)inSender
{
NSDictionary *dict = [inSender userInfo];
NSMenu *menu = [dict objectForKey:@"MenuItem"];
NSLog(@"Testing");
}
In menuChangedItem method, is it possible to know which menu item is clicked(about, q开发者_开发技巧uit ,hideall etc).
Thanks in advance.
Take a look at the documentation:
The userInfo dictionary contains the following information:
@"MenuItem"
- The menu item that was chosen.
Try the following out:
NSMenuItem *item = [dict objectForKey:@"MenuItem"];
NSLog(@"%@", item);
精彩评论