我是 NSOpenPanel/NSSavePanel/NSPanel 的新手。我正在使用 NSOpenPanel 选择一个目录,我的应用程序将对其文件进行迭代并进行一些相当耗时的处理。
我可以在面板上调用 -close ,但这不会将焦点返回到主窗口。我已经阅读了很多关于“关闭”面板的内容 - 但我没有找到任何“关闭”而不是“关闭”面板或窗口的方法。
只是我需要生成一个后台线程(NSOperation)吗?
这就是我的 -chooseDidEnd:returnCode:contextInfo:
-(void) chooseDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
[panel orderOut:self];
[panel release];
if (returnCode == NSFileHandlingPanelOKButton)
{
[progressIndicator startAnimation:self];
[self doLotsOfTimeConsumingWork:[[panel URL] path]];
[progressIndicator stopAnimation:self];
}
}
虽然 NSOpenPanel 确实消失了,但我的 NSProgressIndicator 没有动画,并且主窗口直到-doLotsOfTimeConsumingWork: 完成后才会激活。
更新 刚刚查看了 NSOperationSample 代码,看起来就是这样。