开发者

How can I get a NSMenuItem from a submenu?

开发者 https://www.devze.com 2023-03-23 05:40 出处:网络
I have a reference to the o开发者_如何转开发utermost menu, but I\'m trying to get a reference to an NSMenuItem that\'s nested in a submenu:

I have a reference to the o开发者_如何转开发utermost menu, but I'm trying to get a reference to an NSMenuItem that's nested in a submenu:

NSMenuItem* file_menu = [menu itemWithTitle:@"File];

file_menu is obviously a submenu (NSMenu), but I'm not sure how to get an item out of it's itemarray. I've tried casting it to an NSMenu and performing itemWithTitle as a selector with no luck.

How can I get the first NSMenuItem out of it?


Like this.

NSMenuItem* file_menu = [menu itemWithTitle:@"File"];
if (file_menu.hasSubmenu) {
    NSArray *menu_items = file_menu.submenu.itemArray;
    NSMenuItem *first_item = [menu_items objectAtIndex:0];
}

If the menu item has a sub menu the submenu property will let you access it, you can then access its menu items using the itemArray property.

0

精彩评论

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