2012-03-01 9 views
1

私はココアプログラミングが初めてです。以下のコードを使用して、選択したファイル名をウィンドウに表示します。どうやってやるの? NSLogでウィンドウココアプログラミングで選択したファイルパス/名前を表示

- (IBAction)selectFile:(id)sender { 

    int i; // Loop counter. 

    // Create the File Open Dialog class. 
    NSOpenPanel* openDlg = [NSOpenPanel openPanel]; 

    NSArray *fileTypes = [NSArray arrayWithObjects:@"wmv", @"3gp", @"mp4", @"avi", @"mp3", @"mma", @"wav", nil]; 

    // Enable the selection of files in the dialog. 
    [openDlg setCanChooseFiles:YES]; 

    //Enable multiple selection of files 
    [openDlg setAllowsMultipleSelection:YES]; 

    // Enable the selection of directories in the dialog. 
    [openDlg setCanChooseDirectories:YES]; 

    // Display the dialog. If the OK button was pressed, 
    // process the files. 
    if ([openDlg runModalForDirectory:nil file:nil types:fileTypes] == 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]; 

      NSLog(@"filename::: %@", fileName); 

      // Do something with the filename. 
     } 
    } 
} 

私は名前を取得しています、私が欲しいのは、これらのファイルが選択されているユーザーを表示するには、あまりにもウィンドウ上の名前を示すことです。

どのビューを使用できますか?これを達成する方法は何ですか?

ありがとう

答えて

1

使用NSTextViewまたはNSTextField

+0

行ごとに複数のファイル名が表示されます –

+0

テキストを入力すると表示されます。 1行に1つのファイル名が必要な場合は、各ファイル名の後に改行( '\ n')を付けます。 –

+0

あなたはコードで私を助けることができます、どのように私はこのNSArrayを表示できますか?files = [openDlg filenames]; NSTextViewで –

0
NSArray* files = [openDlg filenames]; 
NSString* fileName; 
    // Loop through all the files and process them. 
    for(i = 0; i < [files count]; i++) 
    { 
     fileName =[fileName stringByAppendingString:[files objectAtIndex:i]; 

     // Do something with the filename. 
    } 

     NSLog(@"filename::: %@", fileName); 
     textView.text=fileName; 
0

runModalForDirectory:file:types:OS X 10.6で廃止されました。代わりにrunModalを使用できます。 setDirectoryURL:を使用してパスを設定し、setAllowedFileTypes:を使用してfileTypesを設定できます。

関連する問題