我的应用程序需要显示选择文件对话框,我正在使用NSOpenPanel来选择文件,代码如下所示:
- (IBAction)sendFileButtonAction:(id)sender{
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( int i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
[self log:fileName];
// Do something with the filename.
}
}
}
一切都很完美,但我只面临一个问题,打开文件时,它显示“打开”和“取消”按钮, 有没有办法将“打开”按钮重命名为“选择”按钮,或者我需要使用其他Cocoa资源。