Completion handler never called for NSSavePanel beginWithCompletionHandler
-
12-11-2019 - |
Question
When I open an NSSavePanel
or NSOpenPanel
instance with beginWithCompletionHandler:
the handler is never called. Instead I see the panel appear for a fraction of a second, before it goes away again without letting the user select a file. When I open the panel with runModal
it works just fine. Here the code:
NSSavePanel *savePanel = [NSSavePanel savePanel];
//[savePanel runModal]; // Works
[savePanel beginWithCompletionHandler:^(NSInteger result){
NSLog(@"DONE"); // Never called, dialog disappears right away
}];
Is there anything I'm missing here?
Thanks, Mark
Solution
Found the problem: in the above code, the savePanel instance is autoreleased as soon as the surrounding method ends. This causes the panel to disappear. The solution is to hold on to the panel reference until the completion block is called.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow