В моем приложении мне нужно показать диалог выбора файла, Я использую 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.