默认情况下,我们使用NSOpenPanel类方法打开一个打开的面板: -beginSheetForDirectory:文件:类型:modalForWindow:modalDelegate:didEndSelector:contextInfo: 但我发现有些软件可以打开带有新文件夹按钮的开放式面板,包含XCode,如何获得它?非常感谢!
答案 0 :(得分:4)
由于NSOpenPanel继承自NSSavePanel,您可以使用NSSavePanel的setCanCreateDirectories
方法,如下所示:
// Show an 'Open' dialog box allowing save folder selection.
NSOpenPanel *open = [NSOpenPanel openPanel];
[open setCanChooseFiles:NO];
[open setAllowsMultipleSelection:NO];
[open setCanChooseDirectories:YES];
[open setCanCreateDirectories:YES];
[open setTitle:@"Open Panel Title"];
[open setPrompt:@"Select Button Title"];
回到OS X 10.2.x天,有一个私有方法,_setIncludeNewFolderButton
,它做了同样的事情,但它在Panther中删除了。不要尝试使用它 - 你的应用程序会崩溃。
答案 1 :(得分:0)
迅速:
let picker = NSOpenPanel()
picker.canCreateDirectories = true
picker.runModal()