T
T
Toly2015-03-23 22:50:14
Cocoa
Toly, 2015-03-23 22:50:14

How to properly close NSOpenPanel?

I need to load a list of files from a directory. To do this, I use the beginSheetModalForWindow:completionHandler: method, then select a directory and click OK. In my case, after OK, the addToList: method is called, which conditionally loads the files and the NSOpenPanel does not close until the addToList: method finishes its work. If you need to call a sheet with an NSProgressIndicator that shows the status of the file upload, then it pops up on top of the NSOpenPanel. I do not like this variety of sheets and I solved this issue by calling the close method for NSOpenPanel before calling the sheet with progress.
For example:

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel beginSheetModalForWindow:window completionHandler:^(NSInteger result) {
        if (result == NSOKButton) {

            [panel close]; //<--- Закрываю sheet c NSOpenPanel

            [NSApp beginSheet:progressSheet modalForWindow:window modalDelegate:nil 
               didEndSelector:nil contextInfo:nil]; //<--- Открываю sheet c индикатором прогресса

            [self addToList:panel.URL]; // <--- загружаю файлы

            [progressSheet orderOut:self];  //
            [NSApp endSheet:progressSheet]; //<--- Закрываю sheet c индикатором прогресса

        }
     }];

Is my solution with calling [panel close] the right choice. And how do you implement such things?
Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question