0

您将如何编写一个按钮来在 Mac 上搜索文件,以便用户可以选择一个文件?该程序将要求用户选择要发送到外部设备的文件。

4

1 回答 1

1

Sounds like you want to use the NSOpenPanel (reference) to allow the user to select a file.

You use it like this:

NSOpenPanel *openPanel = [NSOpenPanel openPanel];
// Configure the panel if necessary using openPanel.whatever = something;
NSInteger result = [openPanel runModal];
if (result == NSOKButton)
{
    NSURL *url = openPanel.URL;
    NSAssert(url.isFileURL, @"Expected a file!");
    NSString *filename = url.path;
}
于 2012-08-14T20:41:47.717 回答