显示文件选择器对话框

发布于 2024-10-19 20:45:01 字数 48 浏览 2 评论 0原文

如何在 Mac OS X 上显示文件选择器对话框?语言是 Objective C。

How do I show a file chooser dialog on Mac OS X? The language is Objective C.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时间你老了 2024-10-26 20:45:01

您搜索的是“NSOpenPanel”,这里是如何使用的示例:

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed

NSInteger clicked = [panel runModal];

if (clicked == NSFileHandlingPanelOKButton) {
    for (NSURL *url in [panel URLs]) {
        // do something with the url here.
    }
}

What you search is 'NSOpenPanel', here a example how to use:

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:YES]; // yes if more than one dir is allowed

NSInteger clicked = [panel runModal];

if (clicked == NSFileHandlingPanelOKButton) {
    for (NSURL *url in [panel URLs]) {
        // do something with the url here.
    }
}
百善笑为先 2024-10-26 20:45:01

那些正在寻找Swift版本的人

let panel                     = NSOpenPanel()
panel.canChooseDirectories    = false
panel.canChooseFiles          = true
panel.allowsMultipleSelection = false
panel.allowedFileTypes        = ["txt"]
let clicked                   = panel.runModal()

if clicked == NSApplication.ModalResponse.OK {
    print("URLS => \(panel.urls)")
}

Those who are looking for Swift version

let panel                     = NSOpenPanel()
panel.canChooseDirectories    = false
panel.canChooseFiles          = true
panel.allowsMultipleSelection = false
panel.allowedFileTypes        = ["txt"]
let clicked                   = panel.runModal()

if clicked == NSApplication.ModalResponse.OK {
    print("URLS => \(panel.urls)")
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文