我是Mac应用程序编程的新手。 我正在使用NSOpenPanel从系统中选择一个文件。一旦我选择了一个文件,然后按下取消/打开按钮,就会执行completionHandler块。
当OpenPanel窗口关闭时,我面临以下问题:
请在下面找到我用来创建NSOpenPanel的代码段。
-(void)openFile
{
//this gives you a copy of an open file dialogue
NSOpenPanel*openPanel = [NSOpenPanel openPanel];
//set the title of the dialogue window
openPanel.title = @"Choose a .zip formate file";
//shoud the user be able to resize the window?
openPanel.showsResizeIndicator = NO;
//should the user see hidden files (for user apps - usually no)
openPanel.showsHiddenFiles = NO;
//can the user select a directory?
openPanel.canChooseDirectories = NO;
//can the user create directories while using the dialogue?
openPanel.canCreateDirectories = NO;
//should the user be able to select multiple files?
openPanel.allowsMultipleSelection = NO;
//an array of file extensions to filter the file list
openPanel.allowedFileTypes = @[@"zip"];
[openPanel beginWithCompletionHandler:^(NSInteger result) {
//if the result is NSOKButton
//the user selected a file
if (result==NSModalResponseOK) {
//Do something
}
else if (result== NSModalResponseCancel)
{
//do something
}
}];
}