2009-10-28 14 views
7

私はObjective-Cを学び、単純なジッパーアプリケーションを開発しようとしていますが、今はダイアログでボタンを挿入する必要があるときに停止し、このボタンを押すとファイルを開くダイアログが開きます圧縮するファイルですが、Open File Dialogを使用したことがありません。その後、どのように開いてユーザの選択したファイルをchar*に保存できますか?ありがとう。ファイルを開くダイアログボックス

私はGNUstep(Linux)を使用しています。他の場合、誰かに

答えて

16

はこの答えを必要とし、ここにある:インパラ@Vlad

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]; 
    } 
18

おかげで、私はOS X 10.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); 
    } 
} 
2

のためのあなたの答えを更新していますOS Xのv10 SP1の+を使用する人々のために、ファーJangtrakoolの答えに置き換えます。

if ([openDlg runModal] == NSOKButton) 

によって
if ([openDlg runModal] == NSModalResponseOK) 
関連する問題