Cocoa:拖放任何文件类型

8
2个回答

12

这可能与问题有关,但如果对某些人有帮助的话,我就加上了:

如果你只是想处理拖放到应用程序图标上的任何文件(不需要是基于文档的应用程序):

在.h文件中:

- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames;
在 .m 文件中:
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames {
    NSLog(@"Files dragged on: %@", fileNames);
}
在你的 xxx.plist 文件中,在 CFBundleDocumentTypes 下创建一个新条目:
<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>*</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>NSFilenamesPboardType</string>
        <key>CFBundleTypeRole</key>
        <string>None</string>
    </dict>
</array>

6
根据这篇文章,您只需要让您的视图注册NSFilenamesPboardType而不是imagePastBoardTypes来接收任意文件类型。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接