Вопрос

I am new to cocoa programming, Using the below code I want to show the selected file names in window. How can I do that?

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

In NSLog I am getting the names, what I want is to show the names on window too, to show the user that these files are selected.

Which view can be used? What is the way to achieve this?

Thanx

Это было полезно?

Решение

Use an NSTextView or an NSTextField.

Другие советы

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;

runModalForDirectory:file:types: is deprecated in OS X v10.6. You could use runModal instead. You can set path using setDirectoryURL:, and you can set fileTypes using setAllowedFileTypes:.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top