"Salva come" in cacao applicazione basato su documenti
-
16-11-2019 - |
Domanda
Sto lavorando a un progetto che crea essenzialmente file tramite uno script di shell usando "SOX".L'applicazione non è basata su documenti, tutto il suo effettuare è chiamare uno script che crea file e non salva internamente alcun dato.Tuttavia, ho bisogno di sollecitare gli utenti in cui salvare il file e quale nome file da utilizzare prima che lo script sia eseguito.Quale sarebbe il modo migliore per avere una finestra di dialogo "Salva come .." per ottenere un filePath / nome file da un utente da passare allo script Shell?
Soluzione
This is pretty straightforward. You tagged this question with NSSavePanel
and that's exactly what you want to use.
- (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
}
}];
}
See also "The Save Panel" in the File System Programming Guide.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow