开发者

Completion handler never called for NSSavePanel beginWithCompletionHandler

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜