Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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

http://sbtraveler.tv/odd/NSOpenPanel.mov

Code:
- (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];
         }
         counter++;

     }

}
 
Last edited:

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.