Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top