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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top