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

| 我正在研究一个项目,该项目实际上是使用\“ sox \”通过shell脚本创建文件的。该应用程序不是基于文档的,它的全部工作是调用一个脚本来创建文件,并且在内部不保存任何数据。但是,我需要在运行脚本之前提示用户保存文件的位置以及要使用的文件名。拥有“另存为.. \”对话框以从用户获取文件路径/文件名并传递到shell脚本的最佳方法是什么?     
已邀请:
这很简单。您用ѭ0tagged标记了这个问题,而这正是您要使用的。
- (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
        }
    }];
}
另请参见《文件系统编程指南》中的“保存面板”。     

要回复问题请先登录注册