开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜