How do I make my program wait for NSOpenPanel to close?

吃可爱长大的小学妹 提交于 2019-12-11 03:26:19

问题


Like the title states, I need to make my program wait until my NSOpenPanel closes. I have the panel open in windowControllerWillLoadNib so that it happens before my document window opens. But what happens is that, it just loads both windows without waiting for the panel to close. How can I make it wait until the open panel is closed and completely finished?


回答1:


use runModal method.

Code example:

int result;
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:nil];
if (result == NSOKButton) {
//your code
}



回答2:


Set up your open panel and then you can do something like this:

if ([openPanel runModal]==NSFileHandlingPanelOKButton) {
    // get the urls
    NSArray *fileURLs = [openPanel URLs];
} else {
    // cancel button was clicked
}

runModal stops the execution of your program until the panel closes.



来源:https://stackoverflow.com/questions/8369210/how-do-i-make-my-program-wait-for-nsopenpanel-to-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!