gpt4 book ai didi

cocoa - 非基于文档的应用程序 Cocoa 中的 "Save As"

转载 作者:行者123 更新时间:2023-12-03 16:05:49 24 4
gpt4 key购买 nike

我正在开发一个项目,该项目本质上是使用“sox”通过 shell 脚本创建文件。该应用程序不是基于文档的,它所做的只是调用创建文件的脚本,并且不会在内部保存任何数据。但是,我需要在运行脚本之前提示用户保存文件的位置以及使用什么文件名。使用“另存为..”对话框从用户获取文件路径/文件名并将其传递给 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"在文件系统编程指南中。

关于cocoa - 非基于文档的应用程序 Cocoa 中的 "Save As",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6065049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com