I'm new to Mac application programming. I'm using NSOpenPanel to select a file from system. Once i select a file, and press Cancel/Open button, completionHandler block is getting executed.
When OpenPanel window is closed, i am facing following issues:
- my main application window is also getting closed even though result of mainAppWindow.visible is 1
- Also, I am not receiving the window close delegate method for main App window.
Please find below the code snippet which I have used to create 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
}
}];
}