私のアプリケーションでは、ファイルの選択ダイアログを表示する必要があります。ファイルを選択できる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.
}
}
}
すべてが完璧に機能しますが、ファイルを開いているときに1つの問題だけが発生し、[開く]と[キャンセル]ボタンが表示されます。開くボタンの名前を[選択]ボタンに変更する方法はありますか、それとも他のCocoaリソースを使用する必要がありますか。