I'm having hard time understanding how to close NSOpenPanel. It does close automatically, but it takes way longer than I want it to take.
Here is my code:
- (IBAction)startProcess:(id)sender
{
NSString *path = [Document openVideoFile]; // open file
// some other method calls here
}
// NSOpenPanel for file picking
+(NSString*) openVideoFile
{
NSOpenPanel *openDialog = [NSOpenPanel openPanel];
//set array of the file types
NSArray *fileTypesArray = [[NSArray alloc] arrayWithObjects:@"mp4", nil];
[openDialog setCanChooseFiles:YES];
[openDialog setAllowedFileTypes:fileTypesArray];
[openDialog setAllowsMultipleSelection:FALSE];
if ([openDialog runModal] == NSFileHandlingPanelOKButton)
{
NSArray *files = [openDialog URLs];
return [[files objectAtIndex:0] path];
}
else
{
return @"cancelled";
}
return nil; // shouldn't be reached
}
Interesting thing is that if user clicks "Cancel", the panel closes right away, but if user selects a file from the list, the panel stays open until the program reaches the end of the startProcess method.
If anyone knows how to close the panel right away, after the user clicks on OK button after selecting a file, I would really appreciate any help!
Thank you!