我很难理解如何关闭 NSOpenPanel。它确实会自动关闭,但它需要的时间比我想要的要长。
这是我的代码:
- (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
}
有趣的是,如果用户单击“取消”,面板会立即关闭,但如果用户从列表中选择一个文件,面板会保持打开状态,直到程序到达 startProcess 方法的末尾。
如果有人知道如何立即关闭面板,在用户选择文件后单击“确定”按钮后,我将非常感谢任何帮助!
谢谢!