[ファイルを開く]ダイアログボックス
-
08-07-2019 - |
質問
Objective-Cを学習してシンプルなジッパーアプリケーションを開発しようとしていますが、ダイアログにボタンを挿入する必要があるときに停止し、このボタンで圧縮するファイルを選択する[ファイルを開く]ダイアログを開きます、[ファイルを開く]ダイアログを使用したことがないので、それを開いて、ユーザーが選択したファイルを char *
に保存する方法を教えてください。ありがとう。
GNUstep(Linux)を使用していることを思い出してください。
解決
他の誰かがこの答えを必要とする場合、ここにあります:
int i;
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// 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];
}
他のヒント
@Vlad the Impalaに感謝します。OSX v10.6 +を使用しているユーザーの回答を更新しています
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModal] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* urls = [openDlg URLs];
// Loop through all the files and process them.
for(int i = 0; i < [urls count]; i++ )
{
NSString* url = [urls objectAtIndex:i];
NSLog(@"Url: %@", url);
}
}
OS X v10.10 +を使用している場合は、Far Jangtrakoolの回答を置き換えてください:
if ( [openDlg runModal] == NSOKButton )
by
if ( [openDlg runModal] == NSModalResponseOK )
所属していません StackOverflow