加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在非基于文档的应用程序Cocoa中“另存为”

发布时间:2020-12-15 18:26:05 所属栏目:安全 来源:网络整理
导读:我正在开发一个基本上通过 shell脚本使用“sox”创建文件的项目.该应用程序不是基于文档的,它所做的只是调用创建文件的脚本,而不是在内部保存任何数据.但是,我需要提示用户保存文件的位置,以及在运行脚本之前要使用的文件名.使用“另存为…”对话框从用户获
我正在开发一个基本上通过 shell脚本使用“sox”创建文件的项目.该应用程序不是基于文档的,它所做的只是调用创建文件的脚本,而不是在内部保存任何数据.但是,我需要提示用户保存文件的位置,以及在运行脚本之前要使用的文件名.使用“另存为…”对话框从用户获取文件路径/文件名以传递给shell脚本的最佳方法是什么?
这非常简单.你用 NSSavePanel标记了这个问题,这正是你想要使用的.
- (IBAction)showSavePanel:(id)sender
{
    NSSavePanel * savePanel = [NSSavePanel savePanel];
    // Restrict the file type to whatever you like
    [savePanel setAllowedFileTypes:@[@"txt"]];
    // Set the starting directory
    [savePanel setDirectoryURL:someURL];
    // Perform other setup
    // Use a completion handler -- this is a block which takes one argument
    // which corresponds to the button that was clicked
    [savePanel beginSheetModalForWindow:someWindow completionHandler:^(NSInteger result){
        if (result == NSFileHandlingPanelOKButton) {
            // Close panel before handling errors
            [savePanel orderOut:self];
            // Do what you need to do with the selected path
        }
    }];
}

另请参见“文件系统编程指南”中的“The Save Panel”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读