Displaying a File Open Dialog in Cocoa with Objective C12/29/06Displaying a File Open Dialog in Cocoa with Objective COk, 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.
}
}
8 comments
Comment from: bbr [Visitor]
This works great!
09/24/08 @ 11:40
Comment from: Jm [Visitor]
02/24/10 @ 18:03
Comment from: Aneeque [Visitor]
03/16/10 @ 03:10
04/08/10 @ 22:40
|