【发布时间】:2014-10-14 11:38:23
【问题描述】:
我是 Cocoa 编程的新手,所以请忽略这可能太明显的事实。
我希望用户选择一个新扩展名为“.red”的文件。 但 NSOpenPanel 似乎并不想要同样的东西。它不会让我选择文件或文件夹。 两者都不。 没有任何。 这是我的代码:
NSOpenPanel *openFile = [NSOpenPanel openPanel];
NSArray *allowTypes = [NSArray arrayWithObjects:@"red", @"RED", nil];
[openFile setAllowsOtherFileTypes:true];
[openFile setAllowsMultipleSelection:false];
[openFile setCanChooseDirectories:false];
[openFile setCanChooseFiles:true];
[openFile setAllowedFileTypes:allowTypes];
if ([openFile runModal] == NSOKButton) {
}
但是当我运行它时,它没有选择任何东西...... 帮忙?
更新: 这是上面代码产生的照片:
我希望能够只选择“Untitled.red”或“RIDE Test.red”文件。
还有!我在“导出的 UTI 类型”下的项目设置中有一个导出的 UTI 类型,并且在文档类型中也有它。
【问题讨论】:
-
而
red是一个注册的UTI类型? -
嗯,我在文档类型和导出的 UTI 类型下的项目设置中添加了 .red 的文件类型。
标签: objective-c macos file cocoa nsopenpanel