从查找器添加项目

发布于 2024-11-05 06:52:39 字数 110 浏览 2 评论 0原文

我有一张桌子,下面有经典的 + - 按钮。 (在苹果机上) 我想按 + 按钮,然后打开一个小查找器来选择一个文件,将其添加到表格中。

我怎样才能做到这一点? 我搜索了开发者参考,但没有找到。

I have a table with the classic + - buttons underneath it. (on mac)
I want to press the + button, and open a little finder to select a file, to add it on the table.

How can I do that?
I searched the developer reference, but didn't find it..

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

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

发布评论

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

评论(1

命硬 2024-11-12 06:52:39

使用 NSOpenPanel< /代码>

有关处理文件和使用打开面板的指南,请参阅 应用程序文件管理指南。

例如:

- (IBAction)addFile:(id)sender
{
    NSInteger result;
    NSArray *fileTypes = [NSArray arrayWithObject:@"html"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    [oPanel setAllowsMultipleSelection:YES];
    [oPanel setDirectory:NSHomeDirectory()];
    [oPanel setCanChooseDirectories:NO];
    result = [oPanel runModal];

    if (result == NSFileHandlingPanelOKButton) {
        for (NSURL *fileURL in [oPanel URLs]) {
            // do something with fileURL
        }
    }
}

另一个使用工作表的例子:

- (IBAction)addFile:(id)sender
{
    NSArray *fileTypes = [NSArray arrayWithObject:@"html"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    [oPanel setAllowsMultipleSelection:YES];
    [oPanel setDirectory:NSHomeDirectory()];
    [oPanel setCanChooseDirectories:NO];
    [oPanel beginSheetModalForWindow:[self window]
        completionHandler:^(NSInteger result) {
        if (result == NSFileHandlingPanelOKButton) {
            for (NSURL *fileURL in [oPanel URLs]) {
                // do something with fileURL
            }
        }
    }];

}

Use NSOpenPanel.

For a guide on dealing with files and using open panels, see the Application File Management guide.

For instance:

- (IBAction)addFile:(id)sender
{
    NSInteger result;
    NSArray *fileTypes = [NSArray arrayWithObject:@"html"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    [oPanel setAllowsMultipleSelection:YES];
    [oPanel setDirectory:NSHomeDirectory()];
    [oPanel setCanChooseDirectories:NO];
    result = [oPanel runModal];

    if (result == NSFileHandlingPanelOKButton) {
        for (NSURL *fileURL in [oPanel URLs]) {
            // do something with fileURL
        }
    }
}

Another example using a sheet:

- (IBAction)addFile:(id)sender
{
    NSArray *fileTypes = [NSArray arrayWithObject:@"html"];
    NSOpenPanel *oPanel = [NSOpenPanel openPanel];

    [oPanel setAllowsMultipleSelection:YES];
    [oPanel setDirectory:NSHomeDirectory()];
    [oPanel setCanChooseDirectories:NO];
    [oPanel beginSheetModalForWindow:[self window]
        completionHandler:^(NSInteger result) {
        if (result == NSFileHandlingPanelOKButton) {
            for (NSURL *fileURL in [oPanel URLs]) {
                // do something with fileURL
            }
        }
    }];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文