13

私はObjective-Cを学び、簡単なジッパーアプリケーションを開発しようとしていますが、ダイアログにボタンを挿入する必要があり、このボタンで圧縮するファイルを選択する[ファイルを開く]ダイアログが開いたときに停止しましたが、 [ファイルを開く]ダイアログを使用したことがない場合、それを開いてユーザーが選択したファイルを?に保存するにはどうすればよいchar*ですか?ありがとう。

GNUstep(Linux)を使用していることを思い出してください。

4

3 に答える 3

21

ありがとう@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);
    }
}
于 2012-11-03T00:12:04.947 に答える
19

他の誰かがこの回答を必要とする場合は、次のとおりです。

 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];
   }
于 2009-11-30T01:46:26.467 に答える
3

OS X v10.10+ を使用している場合は、Far Jangtrakool の回答に置き換えてください。

if ( [openDlg runModal] == NSOKButton )

if ( [openDlg runModal] == NSModalResponseOK )
于 2016-07-02T10:17:24.083 に答える