Отображение выбранного пути / имен файлов в окне - программирование какао - PullRequest
1 голос
/ 01 марта 2012

Я новичок в программировании какао. Используя приведенный ниже код, я хочу показать выбранные имена файлов в окне.Как я могу это сделать?

- (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.
        }
    }
}

В NSLog я получаю имена, я хочу также показать имена в окне, чтобы показать пользователю, что эти файлы выбраны.

Какой вид можно использовать?Как это сделать?

Спасибо

Ответы [ 3 ]

1 голос
/ 01 марта 2012

Используйте NSTextView или NSTextField.

0 голосов
/ 28 мая 2013

runModalForDirectory:file:types: устарела в OS X v10.6. Вместо этого можно использовать runModal. Вы можете установить путь, используя setDirectoryURL:, и вы можете установить fileTypes, используя setAllowedFileTypes:.

0 голосов
/ 01 марта 2012
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;
...