内联菜单未在 ventura mac Catalyst 中显示

问题描述 投票:0回答:1

我的 Mac Catalyst 应用程序基于 Monterey 12.6.3 和 Xcode 14.2 构建,最低版本为 macOS Catalina 11.2。主菜单在 Main.storyboard 中定义,并具有一个包含 3 个内联部分的自定义文件菜单。当应用程序在 Catalina 或 Monterey 中运行时,文件菜单如下所示:

但是当应用程序在 Ventura 上运行时,文件菜单如下所示:

我的所有内联菜单项在 Ventura 中都丢失了,并且我没有在故事板中发现主菜单的任何修改,这将使丢失的项目出现在 Ventura 中。主菜单在故事板中看起来像这样:

我的问题是:如何修改主菜单的情节提要定义,以便蒙特利和文图拉的菜单相同?

我相信可以使用 App Delegate override buildMenuWithBuilder 函数构建我的菜单,但我想知道为什么故事板定义不再在 macOS Catalina 到 Ventura 上工作!

xcode storyboard macos-monterey mac-catalyst macos-ventura
1个回答
0
投票

由于我无法得到这个问题的答案,我决定使用 App Delegate 重写 buildMenuWithBuilder() 来重建菜单:

#if TARGET_OS_UIKITFORMAC
// Fix Issue #009 - Unusable File menu on Ventura                               //leg20230209 - MultiNotes_Catalyst_v1
//  Build File Menu from code instead of using storyboard.
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
{
    [super buildMenuWithBuilder: builder];
    
    // Remove unwanted menus.
    [builder removeMenuForIdentifier:UIMenuServices];
    [builder removeMenuForIdentifier:UIMenuFormat];
    [builder removeMenuForIdentifier:UIMenuClose];
    [builder removeMenuForIdentifier:UIMenuPrint];
    [builder removeMenuForIdentifier:UIMenuFind];

    // NOOP this call when compiling on Catalina and Xcode 12.4 because
    //  macCatalyst 16.0 SDK not available.
#if BUILDING_ON_MONTEREY
    if (@available(macCatalyst 16.0, *)) {
        [builder removeMenuForIdentifier:UIMenuDocument];
    }
#endif
    
    // Build inline "New" menu section.
    UIKeyCommand* newNoteCommand = [UIKeyCommand keyCommandWithInput:@"N" modifierFlags:UIKeyModifierCommand action:@selector(newNoteMenuCMD:)];
    newNoteCommand.title = @"New Note";
    newNoteCommand.discoverabilityTitle = @"Create a new Note in selected Group";

    UIKeyCommand* newGroupCommand = [UIKeyCommand keyCommandWithInput:@"G" modifierFlags:UIKeyModifierCommand+UIKeyModifierShift action:@selector(newGroup)];
    newGroupCommand.title = @"New Group";
    newGroupCommand.discoverabilityTitle = @"Create a new Group in selected Group";

    UIKeyCommand* deleteNoteOrGroupCommand = [UIKeyCommand keyCommandWithInput:@"\b" modifierFlags:UIKeyModifierCommand action:@selector(deleteNoteOrGroup:)];
    deleteNoteOrGroupCommand.title = @"Delete Note or Group";
    deleteNoteOrGroupCommand.discoverabilityTitle = @"Delete selected Note or Group";

    UIKeyCommand* duplicateNoteCommand = [UIKeyCommand keyCommandWithInput:@"R" modifierFlags:UIKeyModifierCommand action:@selector(duplicateNote:)];
    duplicateNoteCommand.title = @"Duplicate Note";
    duplicateNoteCommand.discoverabilityTitle = @"Duplicate selected Note";

    UIMenu* newMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.newmenu" options: UIMenuOptionsDisplayInline children: @[newNoteCommand, newGroupCommand, deleteNoteOrGroupCommand, duplicateNoteCommand]];
    [builder insertChildMenu: newMenu atStartOfMenuForIdentifier: UIMenuFile];

    
    // Build inline "Import" menu section.
    UIKeyCommand* importNotesCommand = [UIKeyCommand keyCommandWithInput:@"" modifierFlags:0 action:@selector(importNotes:)];
    importNotesCommand.title = @"Import Notes…";
    importNotesCommand.discoverabilityTitle = @"Import selected .txt, .html, and .rtf note files from selected folder";     //leg20230220 - MultiNotes_Catalyst_v1

    UIKeyCommand* exportNoteAsHTMLCommand = [UIKeyCommand keyCommandWithInput:@"E" modifierFlags:UIKeyModifierCommand action:@selector(exportNoteAsHTML:)];
    exportNoteAsHTMLCommand.title = @"Export Note As HTML…";
    exportNoteAsHTMLCommand.discoverabilityTitle = @"Export Note as an HTML file";

    UIKeyCommand* exportNoteAsRTFCommand = [UIKeyCommand keyCommandWithInput:@"E" modifierFlags:UIKeyModifierCommand+UIKeyModifierShift action:@selector(exportNoteAsRTF:)];
    exportNoteAsRTFCommand.title = @"Export Note As RTF…";
    exportNoteAsRTFCommand.discoverabilityTitle = @"Export Note as an RTF file";

    UIMenu* importMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.importmenu" options: UIMenuOptionsDisplayInline children: @[importNotesCommand, exportNoteAsHTMLCommand, exportNoteAsRTFCommand]];
    [builder insertChildMenu: importMenu atEndOfMenuForIdentifier: UIMenuFile ];

    
    // Build inline "Print" menu section.
    UIKeyCommand* printNoteCommand = [UIKeyCommand keyCommandWithInput:@"P" modifierFlags:UIKeyModifierCommand action:@selector(printNote:)];
    printNoteCommand.title = @"Print…";
    printNoteCommand.discoverabilityTitle = @"Print selected Note";
    
    UIMenu* printMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.printmenu" options: UIMenuOptionsDisplayInline children: @[printNoteCommand]];
    [builder insertChildMenu: printMenu atEndOfMenuForIdentifier: UIMenuFile ];
}
© www.soinside.com 2019 - 2024. All rights reserved.