문제

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