2009-10-28 20 views
7

मैं उद्देश्य-सी सीख रहा हूं और एक साधारण जिपर एप्लिकेशन विकसित करने की कोशिश कर रहा हूं, लेकिन जब मैं अपने संवाद में एक बटन डालने की ज़रूरत है, तब मैं रुक गया और यह बटन एक ओपन फाइल डायलॉग खोलता है जो चुन देगा एक फ़ाइल को संपीड़ित करने के लिए, लेकिन मैंने कभी भी एक ओपन फ़ाइल संवाद का उपयोग नहीं किया, फिर मैं इसे कैसे खोल सकता हूं और उपयोगकर्ता चयनित फ़ाइल को char* में संग्रहीत कर सकता हूं? धन्यवाद।ओपन फाइल डायलॉग बॉक्स

याद रखें कि मैं जीएनयूस्टेप (लिनक्स) का उपयोग कर रहा हूं।

उत्तर

16

किसी और मामले में किसी को इस सवाल का जवाब की जरूरत है, यहाँ यह है:

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

इम्पाला मैं लोग हैं, जो ओएस एक्स v10.6 का उपयोग के लिए अपने जवाब को अद्यतन करने हूँ @Vlad धन्यवाद +

// 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

०१२३५१६४१०६ द्वारा

if ([openDlg runModal] == NSOKButton) 

: लोग हैं, जो का उपयोग ओएस एक्स v10.10 + के लिए, सुदूर Jangtrakool जवाब में की जगह

if ([openDlg runModal] == NSModalResponseOK) 
संबंधित मुद्दे