Resolved NSOpenPanel Problem

Discussion in 'Mac Programming' started by larswik, Dec 17, 2012.

  1. larswik, Dec 17, 2012
    Last edited: Dec 17, 2012

    macrumors 68000

    Sep 8, 2006
    When I open an NSOpenPanel to get a file and click OK It is not responding to the OK button the first time? If seems to disappear then reappear with an empty folder. This causes me to have to back out of the folder and go back into it to select the item again. After that it loads just fine? I have googled a looked at other examples and mine seems no different? I made a demo video to better demonstrate the issue here

    - (IBAction)importItem:(id)sender{
        NSOpenPanel *openDlg = [NSOpenPanel openPanel];;
        NSString *pathName = @"/Users/larspro/Documents/ERad files/items database";
        [openDlg setDirectoryURL:[NSURL URLWithString:pathName]];
        [openDlg setCanChooseFiles:YES];
        [openDlg setCanChooseDirectories:NO];
        [openDlg runModal];
        NSInteger result = [openDlg runModal];
        if (result == NSFileHandlingPanelCancelButton) {
            [openDlg orderOut:self];
         if ( result == NSOKButton) {
             if (counter == 0) {
                 item1Array = [[NSMutableArray alloc] initWithContentsOfURL:openDlg.URL];
                 NSImage *importImage = [[NSImage alloc] initWithData:[item1Array objectAtIndex:0]];
                 item1ImageView.image = importImage;
                 firstName.stringValue = [item1Array objectAtIndex:1];
                 [openDlg orderOut:self];
             if (counter == 1) {
                 item2Array = [[NSMutableArray alloc] initWithContentsOfURL:openDlg.URL];
                 NSImage *importImage = [[NSImage alloc] initWithData:[item2Array objectAtIndex:0]];
                 item2ImageView.image = importImage;
                 secondName.stringValue = [item2Array objectAtIndex:1];
                 [openDlg orderOut:self];
             if (counter == 2) {
                 item3Array = [[NSMutableArray alloc] initWithContentsOfURL:openDlg.URL];
                 NSImage *importImage = [[NSImage alloc] initWithData:[item3Array objectAtIndex:0]];
                 item3ImageView.image = importImage;
                 thirdName.stringValue = [item3Array objectAtIndex:1];
                 [openDlg orderOut:self];
             if (counter == 3) {
                 item4Array = [[NSMutableArray alloc] initWithContentsOfURL:openDlg.URL];
                 NSImage *importImage = [[NSImage alloc] initWithData:[item4Array objectAtIndex:0]];
                 item4ImageView.image = importImage;
                 forthName.stringValue = [item4Array objectAtIndex:1];
                 [openDlg orderOut:self];
  2. thread starter macrumors 68000

    Sep 8, 2006
    Discovered the problem. I did not need the code [openDlg runModal]. It seems that just the NSOpenPanel *openDlg = [NSOpenPanel openPanel]; presents the modalWindow, this caused the redundant opening of the windows.

Share This Page