2011-12-03 24 views
1

就像標題狀態一樣,我需要讓我的程序等到我的NSOpenPanel關閉。我在windowControllerWillLoadNib中打開面板,以便在我的文檔窗口打開前發生。但是會發生的是,它只是加載兩個窗口而不等待面板關閉。我如何等待直到打開的面板關閉並完全完成?如何讓我的程序等待NSOpenPanel關閉?

回答

2

使用runModal方法。

代碼示例:

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

設置打開的面板,然後你可以做這樣的事情:

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

runModal直到面板關閉停止程序的執行。