« Happy New Year!Export Youtube Videos to the iPod »

Displaying a File Open Dialog in Cocoa with Objective C

12/29/06

Permalink 09:27:23 pm, by rekle Email , 135 words   English (US)
Categories: Cocoa

Displaying a File Open Dialog in Cocoa with Objective C

Ok, so I've been learning Mac programming using Objective-C. I'm still a horrible rank amateur at this stuff, but here's one thing I've learned. Here is an example of how to display a modal File Open dialog box...


int i; // Loop counter.

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

// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles: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] == 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];

        // Do something with the filename.
    }
}

September 2010
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Copyright © 2005 - 2010, Rick Ekle

Comments? Contact me at rick@ekle.us or visit me on Twitter at @rekle

Search

XML Feeds

User tools

powered by free blog software