私は基本的に「sox」を使用してシェルスクリプトを介してファイルを作成するプロジェクトに取り組んでいます。アプリケーションはドキュメントベースではなく、ファイルを作成するスクリプトを呼び出すだけで、データを内部的に保存しません。ただし、スクリプトを実行する前に、ファイルの保存場所と使用するファイル名をユーザーに確認する必要があります。「名前を付けて保存」ダイアログボックスを使用して、ユーザーからファイルパス/ファイル名を取得してシェルスクリプトに渡すための最良の方法は何でしょうか。
3812 次
1 に答える
21
これは非常に簡単です。あなたはこの質問にタグを付けました、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
}
}];
}
『ファイルシステムプログラミングガイド』の「保存パネル」も参照してください。
于 2011-05-19T21:38:57.000 に答える