Adding item to NSMenu with action selector preset

≯℡__Kan透↙ 提交于 2019-12-06 14:49:12

If you want the action to be triggered against your object, you have to specify a target for the new NSMenuItem:

NSMenuItem *item = [statusMenu insertItemWithTitle:[NSString stringWithFormat:@"%d - %@", convo.newMessagesCount, convo.ewName] action:@selector(openEchowavesURL:) keyEquivalent:@"" atIndex:0];
[item setTarget:self]; // or whatever target you want

If you don't do it, then the NSResponder chain will be walked until an object responds to the selector.

Actions need a target or else they get sent to nil and then new rules apply.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!