Окно модели NSOpenPanel убивает главное окно приложения

Я новичок в разработке приложений для Mac. Я использую NSOpenPanel, чтобы выбрать файл из системы. После того, как я выбрал файл и нажал кнопку "Отмена / Открыть", выполняется завершение блока Handler.

Когда окно OpenPanel закрыто, я сталкиваюсь со следующими проблемами:

  1. мое главное окно приложения также закрывается, хотя результат mainAppWindow.visible равен 1
  2. Кроме того, я не получаю метод делегата закрытия окна для основного окна приложения.

Ниже приведен фрагмент кода, который я использовал для создания 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 ответов

Другие вопросы по тегам