NSOpenPanel模型窗口杀死主应用程序窗口

时间:2016-12-20 13:52:57

标签: objective-c cocoa nsopenpanel nssavepanel

我是Mac应用程序编程的新手。 我正在使用NSOpenPanel从系统中选择一个文件。一旦我选择了一个文件,然后按下取消/打开按钮,就会执行completionHandler块。

当OpenPanel窗口关闭时,我面临以下问题:

  1. 即使mainAppWindow.visible的结果为1
  2. ,我的主应用程序窗口也会关闭
  3. 另外,我没有收到主App窗口的窗口关闭委托方法。
  4. 请在下面找到我用来创建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
                }
        }];  
    }
    

0 个答案:

没有答案