Search code examples
objective-ccocoansopenpanel

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


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?


Solution

  • use runModal method.

    Code example:

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