【问题标题】:Cocoa: Drag and Drop any file typeCocoa:拖放任何文件类型
【发布时间】:2011-05-20 09:19:30
【问题描述】:
【问题讨论】:
标签:
objective-c
cocoa
drag-and-drop
file-type
【解决方案1】:
有点相关,但添加这个以防对某人有帮助:
如果您只是想处理拖到应用程序图标上的任何文件(不需要是基于文档的应用程序):
在.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>
【解决方案2】:
根据post 判断,您可能只需要为NSFilenamesPboardType 而不是imagePastBoardTypes 注册视图即可接收任意文件类型。