【问题标题】:Remove the "Open Recent" menu item in Cocoa apps删除 Cocoa 应用程序中的“打开最近”菜单项
【发布时间】:2011-06-10 14:09:17
【问题描述】:

我发现一堆人问这个(删除或禁用最近项目子菜单)并且没有答案。

经过一番调查......问题是 Apple 已经秘密地将特定菜单硬编码为总是出现 - 即使你删除它,NSWindowController 也会默默地重新创建它。

【问题讨论】:

    标签: objective-c cocoa macos nsmenu


    【解决方案1】:

    编辑:有些白痴想改写我的答案。别。或者我会删除它。根据最初拒绝编辑的审稿人:“这个编辑太小了;建议的编辑应该是解决帖子中多个问题的实质性改进。”所以:不要。


    Apple 有一个官方解决方法(他们勉强接受了硬编码菜单的错误):

    http://developer.apple.com/library/mac/#qa/qa2001/qa1289.html

    设置 IBOutlet 后,似乎可以正常工作:

    @property( nonatomic, retain) IBOutlet NSMenu* fileMenu;
    

    ...并确保您的 AppDelegate 类在 MainWindow.xib 中表示(例如,使用蓝色立方体对象,并将该类设置为您的 AppDelegate 的任何类)...这样您就可以连接文件菜单本身在 NIB 中直接连接到您的应用程序委托。

    编辑:实际上,修改 - Apple 的源代码无法使用 Xcode4 正确编译,产生编译器警告。你想要这个:

    NSInteger openDocumentMenuItemIndex = [self.fileMenu indexOfItemWithTarget:nil andAction:@selector(openDocument:)];
    
    if (openDocumentMenuItemIndex>=0 &&
        [[self.fileMenu itemAtIndex:openDocumentMenuItemIndex+1] hasSubmenu])
    {
        // APPLE'S COMMENT: We'll presume it's the Open Recent menu item, because this is
        // APPLE'S COMMENT: the heuristic that NSDocumentController uses to add it to the
        // APPLE'S COMMENT: File menu
        [self.fileMenu removeItemAtIndex:openDocumentMenuItemIndex+1];
    }
    

    【讨论】:

      猜你喜欢
      • 2016-04-24
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      • 2012-03-29
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多