私はObjective-Cを学び、簡単なジッパーアプリケーションを開発しようとしていますが、ダイアログにボタンを挿入する必要があり、このボタンで圧縮するファイルを選択する[ファイルを開く]ダイアログが開いたときに停止しましたが、 [ファイルを開く]ダイアログを使用したことがない場合、それを開いてユーザーが選択したファイルを?に保存するにはどうすればよいchar*
ですか?ありがとう。
GNUstep(Linux)を使用していることを思い出してください。
私はObjective-Cを学び、簡単なジッパーアプリケーションを開発しようとしていますが、ダイアログにボタンを挿入する必要があり、このボタンで圧縮するファイルを選択する[ファイルを開く]ダイアログが開いたときに停止しましたが、 [ファイルを開く]ダイアログを使用したことがない場合、それを開いてユーザーが選択したファイルを?に保存するにはどうすればよいchar*
ですか?ありがとう。
GNUstep(Linux)を使用していることを思い出してください。
ありがとう@Vlad the Impala OS X v10.6+を使用している人々の回答を更新しています
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModal] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* urls = [openDlg URLs];
// Loop through all the files and process them.
for(int i = 0; i < [urls count]; i++ )
{
NSString* url = [urls objectAtIndex:i];
NSLog(@"Url: %@", url);
}
}
他の誰かがこの回答を必要とする場合は、次のとおりです。
int i;
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
// Loop through all the files and process them.
for( i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
}
OS X v10.10+ を使用している場合は、Far Jangtrakool の回答に置き換えてください。
if ( [openDlg runModal] == NSOKButton )
に
if ( [openDlg runModal] == NSModalResponseOK )