Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 在NSStatusItem应用程序中显示NSOpenPanel_Cocoa_Macos_Nswindow_Nsstatusitem - Fatal编程技术网

Cocoa 在NSStatusItem应用程序中显示NSOpenPanel

Cocoa 在NSStatusItem应用程序中显示NSOpenPanel,cocoa,macos,nswindow,nsstatusitem,Cocoa,Macos,Nswindow,Nsstatusitem,我正在编写一个没有NSWindow的状态项应用程序。当用户单击状态项时,我将打开NSOpenPanel。当应用程序不使用NSWindow时,如何做到这一点 谢谢。将其作为模式窗口而不是工作表运行。将其作为模式窗口而不是工作表运行。在状态项的iAction方法中,调用以下命令: window = [[NSApp currentEvent] window]; 然后可以将该窗口传递给NSOpenPanel的beginSheetModalForWindow:completionHandler:以将打开

我正在编写一个没有NSWindow的状态项应用程序。当用户单击状态项时,我将打开NSOpenPanel。当应用程序不使用NSWindow时,如何做到这一点


谢谢。

将其作为模式窗口而不是工作表运行。

将其作为模式窗口而不是工作表运行。

在状态项的iAction方法中,调用以下命令:

window = [[NSApp currentEvent] window];
然后可以将该窗口传递给NSOpenPanel的beginSheetModalForWindow:completionHandler:以将打开的面板显示为工作表


您可能会发现,状态项本身会随着工作表的出现而卷曲并消失,但当您关闭工作表时,它会重新出现。

在状态项的iAction方法中,将其称为:

window = [[NSApp currentEvent] window];
然后可以将该窗口传递给NSOpenPanel的beginSheetModalForWindow:completionHandler:以将打开的面板显示为工作表


您可能会发现,当工作表出现时,状态项本身会卷曲并消失,但当您关闭工作表时,状态项会重新出现。

您只需从NSMenuItem的操作中调用打开的面板,如下所示:

NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setAllowsMultipleSelection:YES];
    [panel setCanChooseDirectories:YES];

    NSUInteger result = [panel runModal];
    NSMutableArray *paths = [NSMutableArray array];

    if(result == NSFileHandlingPanelOKButton) {
        for (NSURL *url in [panel URLs]) {
            NSLog(@"%@", url);
        }
    }

您只需通过NSMenuItem的操作调用打开的面板,如下所示:

NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setAllowsMultipleSelection:YES];
    [panel setCanChooseDirectories:YES];

    NSUInteger result = [panel runModal];
    NSMutableArray *paths = [NSMutableArray array];

    if(result == NSFileHandlingPanelOKButton) {
        for (NSURL *url in [panel URLs]) {
            NSLog(@"%@", url);
        }
    }

完美,这正是我需要的。完美,这正是我需要的。