Answer the question
In order to leave comments, you need to log in
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 индикатором прогресса
}
}];
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question